function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
chandru chandruchandru chandru 

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.

CharuDuttCharuDutt
Hii Chandru
Try Below Code
trigger accountcontat on Account (after update){
if(trigger.IsAfter && trigger.Isupdate){
for(Account Acc : trigger.new){

if(Acc.Match_Billing_Address__c){
//code logic
}

}
}
}
Please Makrk It As Best Answer If It Helps
Thank You!
SwethaSwetha (Salesforce Developers) 
HI Chandru,

Recommend reviewing these similar posts

https://developer.salesforce.com/forums/?id=9060G000000Bi4JQAS
https://developer.salesforce.com/forums/?id=906F0000000D6AbIAK
trigger AccountAddressTrigger on Account (before insert) {

    for(Account a : Trigger.New) {
        
        if (a.Match_Billing_Address__c == false)
            return;
    
    if ( a.BillingAddress != null && a.Match_Billing_Address__c == true)
       
            a.ShippingCity = a.BillingCity; 
            a.ShippingCountry = a.BillingCountry;
            a.ShippingPostalCode = a.BillingPostalCode;
            a.ShippingState = a.BillingState;
            a.ShippingStreet = a.BillingStreet;
     
}
}

If this information helps, please mark the answer as best. Thank you
Shubham Jain 338Shubham Jain 338
Hi Chandru,

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