We updated an account that had 'Match_Billing_Address__c' set to false. We expected the Apex trigger not to fire, but it did. Make sure the Apex trigger fires only if 'Match_Billing_Address__c' is true.
Execute in before or after context according to requirement. If need to update anything on the account then go in before context and if have to perform logic on a different object then go in after context.
trigger AccountTrigger on Account (before insert, before update) { for (Account acc : Trigger.new) { if ((Trigger.isInsert || (Trigger.isUpdate && Trigger.oldMap.get(acc.Id).Match_Billing_Address__c != acc.Match_Billing_Address__c)) && acc.Match_Billing_Address__c) { // excute your logic } } }
If this information helps, please mark the answer as best. Thanks Shubham
Try Below Code Please Makrk It As Best Answer If It Helps
Thank You!
Recommend reviewing these similar posts
https://developer.salesforce.com/forums/?id=9060G000000Bi4JQAS
https://developer.salesforce.com/forums/?id=906F0000000D6AbIAK
If this information helps, please mark the answer as best. Thank you
Execute in before or after context according to requirement. If need to update anything on the account then go in before context and if have to perform logic on a different object then go in after context.
trigger AccountTrigger on Account (before insert, before update) {
for (Account acc : Trigger.new) {
if ((Trigger.isInsert || (Trigger.isUpdate && Trigger.oldMap.get(acc.Id).Match_Billing_Address__c != acc.Match_Billing_Address__c)) && acc.Match_Billing_Address__c) {
// excute your logic
}
}
}
If this information helps, please mark the answer as best.
Thanks Shubham