function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Anamika JakhmolaAnamika Jakhmola 

Hi I am stuck with an error shown in below while completing the trailhead on Apex Trigger - Get Started with Apex.

"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)".

Error-   Challenge Not yet complete... here's what's wrong: 
There was an unexpected error in your org which is preventing this assessment check from completing: System.DmlException: Insert failed. First exception on row 0; first error: UNKNOWN_EXCEPTION, Use one of these records?: []

below is the code-
trigger AccountAddressTrigger on Account (before insert, before update) {

    try{
for(Account act : Trigger.new){
        If(act.Match_Billing_Address__c == true && act.BillingPostalCode!= null)
        {
            act.ShippingPostalCode=act.BillingPostalCode;
        }
}
}
catch(DmlException e)
{
    system.debug('cause'+e.getcause());
}

}
  

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