Skip to main content 3 月 5 日~ 6 日にサンフランシスコで開催される TDX (Salesforce+ でも配信) で「Developer Conference for the AI Agent Era (AI エージェント時代に向けた開発者向けカンファレンス)」にぜひご参加ください。お申し込みはこちら
Eddie Lott (Arbola Inc) が「#Apex」で質問
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 件の回答
  1. 2017年12月9日 19:26

    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