I was doing Apex trigger challenge.
Create an Apex Trigger
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. Fire the trigger before inserting an account or updating an account.
Pre-Work:
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.
My code was,
trigger AccountAddressTrigger on Account (before insert, before update) {
for(Account a:Trigger.new) {
if(a.Match_Billing_Address__c == true)
{
a.ShippingPostalCode = a.BillingPostalCode;
}
}
}
It shows an error even after i verified my trigger by making changes on account object. error is-
Challenge not yet complete in My Trailhead Playground 1
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.
Kindly help me.
5 réponses
Hi Mo,
Your code looks fine. Could you please check if there is any other trigger/PB/flow with same functionality.
You can use Where is this Used on the field.