+ 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.