简体   繁体   中英

Salesforce Apex Triggers - How to check if field is included in update trigger?

I would really appreciate if someone can guide me to check if a particular field is included in update call inside a before/after update trigger. Many thanks.

All fields are always present in the trigger regardless of whether they are dirty or not, to ascertain if a specific field has been modified you have to retrieve a previous version of the row using oldMap map which is a Map<ID, sObject> and compare the values in old and new. For example

trigger CaseOnParticularFieldUpdate on Case (before update) {
    for (Case c: Trigger.new) {
        Case oldCase = Trigger.oldMap.get(c.ID);
        if (c.Field != oldCase.Field) {
            // field was updated, do some magic here
        }
    }
}

Trigger will include all fields of that sobject for which it is invoked. You can check previous(old) value and current(new) value of any field in that object and can compare it and can do the operation accordingly.

Hope it helps you.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM