Skip to main content The Trailblazer Community will be unavailable from 2/1/2025 to 2/2/2025. Please plan your activities accordingly.
Taking the challenge for the Getting Started With APEX triggers and found that the trigger code below did not work and had the stranger problem of Changing the Match_Billing_Address__c field to True whenever i tried to save an account.  After a few exasperating hours, i changed I (a.Match_Billing_Address__c=true) to  (a.Match_Billing_Address__c<>false) and it all started working and I passed the challenge.   I would be grateful for any explanation of this behavior.

 

trigger AccountAddressTrigger on Account (before insert, before update) {

    For (Account a : Trigger.new) { 

        If (a.Match_Billing_Address__c=true) {

        system.debug(a.Match_Billing_Address__c);

        a.ShippingPostalCode=a.BillingPostalCode;

    }    

    }

}

 
1 answer
  1. Dec 9, 2017, 7:26 PM

    It should have been:

    if(a.Match_Billing_Addtess__c == true)

    What you were doing - and this will explain the "stranger problem" - was setting that checkbox to true ("=" assigns a value, "==" evaluates equality) which then caused the IF statement to evaluate to TRUE.

0/9000