Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Salesforce by (13.1k points)
edited by

I have created an Apex trigger, and I was trying to run a trailhead but it always throws an error:

"Challenge not yet complete... here's what's wrong: Executing the trigger did not work as expected. "

Herewith I have attached my code:

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

    for(Account a : [SELECT Id FROM Account WHERE  Match_Billing_Address__c = TRUE AND BillingPostalCode != NULL])

    {

        a.ShippingPostalCode = a.BillingPostalCode;

        update a;        

    }//end for     

}

Can anyone help me with this?

1 Answer

0 votes
by (26.7k points)
edited by

Basically, there is some issue with your code, your trigger should be looks like this:

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

    //Iterate all accounts that is updated or inserted.

    for(Account acc :Trigger.New){

        //if match is true set values.

        if(acc.Match_Billing_Address__c){

            acc.ShippingPostalCode = acc.BillingPostalCode;

        }

    }

}

I hope this will help.

Want to become a Salesforce expert? Join salesforce apex training now!!

Want to know more about Salesforce? Watch this following tutorial video on Salesforce Platform Developer 1 Certification Training:

Related questions

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...