简体   繁体   English

Salesforce Apex触发器 - 如何检查更新触发器中是否包含字段?

[英]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. 所有字段始终存在于触发器中,无论它们是否为脏,要确定特定字段是否已被修改,您必须使用oldMap映射检索该行的先前版本,该映射是Map<ID, sObject>并进行比较旧的和新的价值观。 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. 触发器将包括调用它的那个sobject的所有字段。 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. 希望它能帮到你。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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