Skip to main content

Add a checkbox field to the Account object:

  • Field Label: Match Billing Address
  • Field Name: Match_Billing_Address Note: The resulting API Name should be Match_Billing_Address__c.
  • Create an Apex trigger:
    • Name: AccountAddressTrigger
    • Object: Account
    • Events: before insert and before update
    • Condition: Match Billing Address is true
    • Operation: set the Shipping Postal Code to match the Billing Postal Code

 

Created a custom checkbox field with 

  • Field Label: Match Billing Address
  • Field Name: Match_Billing_Address
  • API Name: Match_Billing_Address__c.

Trigger written:

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

for(Account a:Trigger.new){

if(a.Match_Billing_Address__c == true){

a.ShippingPostalCode = a.BillingPostalCode;         

} } }

Issue:

We updated an account that had 'Match_Billing_Address__c' set to false. We expected the trigger not to fire, but it did. Make sure the trigger fires only if 'Match_Billing_Address__c' is true.

 

Can someone help me with what I'm missing? #Trailhead Challenges #Apex Trigger #Apex

 

Source: https://trailhead.salesforce.com/en/content/learn/modules/apex_triggers/apex_triggers_intro

8 respuestas
  1. 13 jul 2021, 05:55

    Hi Joel,

     

    "Try this one."

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

    for(Account a:Trigger.New){

    if(a.Match_Billing_Address__c && (a.BillingPostalCode != null || a.BillingPostalCode!=' ' )){

    a.ShippingPostalCode = a.BillingPostalCode;

    }

    }

    }

     

    If you find your Solution then mark this as the best answer.

     

    Thank you!

     

    Regards 

    Suraj Tripathi

0/9000