简体   繁体   中英

how to fire a salesforce trigger only if we update a custom field

有没有一种方法可以在salesforce custom object上创建触发器,该触发器仅在我们更新一个自定义字段时才触发,而不是在每次更新整个对象时才触发

In General, the triggers are fired whenever there is a change to any/all fields in the object. What you can do is compare the value in trigger.old with the value in trigger.new

eg:

trigger TestTrigger on Account (before update) {
  for(Account a : Trigger.new){
            if(a.Active__c != Trigger.oldMap.get(a.id).Active__c)
                System.debug('change in Active field');


        }

}

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