• Sabine Scheuring
  • NEWBIE
  • 15 Points
  • Member since 2021

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 3
    Replies
The task is to create an Apex trigger that sets an account’s Shipping Postal Code to match the Billing Postal Code if the Match Billing Address option is selected. As per the task, I created the checkbox "Match Billing Account" on the Accounts Object first. Here is the code I used which seems to work for other users: 

trigger AccountAddressTrigger on Account (before insert, before update){
     for(Account account: Trigger.new){
        if((account.Match_Billing_Address__c==true)&&(account.BillingPostalCode != NULL)){    
       account.ShippingPostalCode = account.BillingPostalCode;  
            }
        } 
    }

The Error is as following: 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.

I tried different Playgrounds but always end up with the same error. 
The task is to create an Apex trigger that sets an account’s Shipping Postal Code to match the Billing Postal Code if the Match Billing Address option is selected. As per the task, I created the checkbox "Match Billing Account" on the Accounts Object first. Here is the code I used which seems to work for other users: 

trigger AccountAddressTrigger on Account (before insert, before update){
     for(Account account: Trigger.new){
        if((account.Match_Billing_Address__c==true)&&(account.BillingPostalCode != NULL)){    
       account.ShippingPostalCode = account.BillingPostalCode;  
            }
        } 
    }

The Error is as following: 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.

I tried different Playgrounds but always end up with the same error. 
Hi All,

Can anyone please help me with bellow challenge.


Create an Apex trigger for Account that matches Shipping Address Postal Code with Billing Address Postal Code based on a custom field.
For this challenge, you need to create a trigger that, before insert or update, checks for a checkbox, and if the checkbox field is true, sets the Shipping Postal Code (whose API name is ShippingPostalCode) to be the same as the Billing Postal Code (BillingPostalCode).The Apex trigger must be called 'AccountAddressTrigger'.
The Account object will need a new custom checkbox that should have the Field Label 'Match Billing Address' and Field Name of 'Match_Billing_Address'. The resulting API Name should be 'Match_Billing_Address__c'.
With 'AccountAddressTrigger' active, if an Account has a Billing Postal Code and 'Match_Billing_Address__c' is true, the record should have the Shipping Postal Code set to match on insert or update.

For above challenge i tried with following code but looks like it doesnt mach the requirement.

trigger AccountAddressTrigger on Account (before insert, before update) {
    for(Account a : Trigger.new){
        If (a.Match_Billing_Address__c = true) {
            /*ShippingPostalCode = BillingPostalCode;*/
        }   
    } 

}

Please help me