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
Bareera NoorBareera Noor 

Trailhead Error: Apex Triggers Get Started with Apex Triggers

I am working on Trailhead challenge : Create an Apex trigger for Account that matches Shipping Address Postal Code with Billing Address Postal Code based on a custom field.
I first wrote this code:
 for(Account a : Trigger.new){
        If (a.Match_Billing_Address__c = true && a.BillingPostalCode!=Null) {
            a.ShippingPostalCode = a.BillingPostalCode;
        }   
    }
}
Error Message I am getting is : "Challenge not yet complete... here's what's wrong:
Setting 'Match_Billing_Address__c' to false updated the records anyway. The trigger should only act when Match_Billing_Address__c is true."


Below is the code that I saw it in youtube tutorial
trigger AccountAddressTrigger on Account (before insert, before update) {
 
    for(Account a : Trigger.new){
        If (a.Match_Billing_Address__c == true) 
            a.ShippingPostalCode = a.BillingPostalCode;
         
    }
 
}
I am getting following error message:
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: Delete failed. First exception on row 0 with id 00141000013PNVjAAO; first error: DELETE_FAILED, Your attempt to delete TestMyCodeCo could not be completed because it is associated with the following cases.: 00001052 Your attempt to delete TestMyCodeCo could not be completed because some opportunities in that account were closed won. The opportunities that could not be deleted are shown below.: Opp : []

 
Marc D BehrMarc D Behr
Did you start the module with a fresh trailhead playgound? It sounds like some other data iin the org is interferring with the testing.
Bareera NoorBareera Noor
I am doing this in my developer account.
Marc D BehrMarc D Behr
I would suggest that your create a new trailhead playground to do the module. Many modules assume that you have no other data (other than what is provided) in the org.
Suraj Tripathi 47Suraj Tripathi 47
Hi Bareera,

Try this code.
trigger AccountAddressTrigger5 on Account (before insert , before update) {
    for(Account acc:Trigger.New){
        if(acc.Match_Billing_Address__c && (acc.BillingPostalCode != null || acc.BillingPostalCode!=' ' )){
           acc.ShippingPostalCode = acc.BillingPostalCode;
        }
    }
}


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


Thank you!

Regards 
Suraj Tripathi