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
roopak mudiliroopak mudili 

Error generated during Trailhead Challenge

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 0013600000LcVd3AAF; first error: FIELD_CUSTOM_VALIDATION_EXCEPTION, Cannot delete account with related opportunities.: []

Go this error while working on the first challenge under Apex Triggers in Developer Beginner Trailhead.

Create an Apex trigger for Account that matches Shipping Address Postal Code with Billing Address Postal Code based on a custom field.

And my solution for the same is as follows:

trigger AccountAddressTrigger on Account (before insert, before update){
    
    for (Account a : Trigger.new) {
        if(a.BillingPostalCode != null && a.Match_Billing_Address__c == true){
            a.ShippingPostalCode = a.BillingPostalCode;
        }
    }


}

 
Best Answer chosen by roopak mudili
Amit Chaudhary 8Amit Chaudhary 8
Your code look good to me .

Please check you any trigger you have on Account object which is creating opportunity ? If yes then please deactivate the trigger and try again.

Please try to activate all other trigger and validation and try again

Let us know if that will help you
 

All Answers

Amit Chaudhary 8Amit Chaudhary 8
Your code look good to me .

Please check you any trigger you have on Account object which is creating opportunity ? If yes then please deactivate the trigger and try again.

Please try to activate all other trigger and validation and try again

Let us know if that will help you
 
This was selected as the best answer
roopak mudiliroopak mudili
@Amit ji its working.......Thanks for you help
Md Dilowar HussainMd Dilowar Hussain
Hi, 

I have created a custom checkbox field as "Match Billing Address" with the API name, "Match_Billing_Address__c". Below shows the screen shot.

User-added image

Below is my code in DEV console.

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

But the below error message is getting displaying while checking the challange.

Challenge Not yet complete... here's what's wrong: 
A field with an API Name 'Match_Billing_Address__c' does not exist on the Account object.

Request your suggestions to get rid of the same.
Amit Chaudhary 8Amit Chaudhary 8
If look like you create custom field "Match_Billing_Address__c" on custom object Account clean info not on standard Account Object.
Please create field on account object
Md Dilowar HussainMd Dilowar Hussain
Hi Amit, 

I am able to find the mistake out. It's working now. Thanks. :):)
Michal KaparMichal Kapar
Deactive AccountDeletion Account Trigger from one of another Trailhead module.