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
Eddie LottEddie Lott 

Unusual Trigger Problem

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;
    }    
    }
}

 
Best Answer chosen by Eddie Lott
Paul S.Paul S.
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.