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
Akshada Sonavane 2Akshada Sonavane 2 

Error while checking a trigger challebge on trailhead(trigger to set the Shipping Postal Code (whose API name is ShippingPostalCode) to be the same as the Billing Postal Code (BillingPostalCode).if the checkbox 'Match_Billing_Address__c' is true)

For this trigger trailhead question:
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).

The Apex trigger must be called 'AccountAddressTrigger'.
The Account object will need a new custom checkbox that should have the Field Label 'Match Billing Address' and Field Name of 'Match_Billing_Address'. The resulting API Name should be 'Match_Billing_Address__c'.
With 'AccountAddressTrigger' active, if an Account has a Billing Postal Code and 'Match_Billing_Address__c' is true, the record should have the Shipping Postal Code set to match on insert or update.


Getting following error while checking the challenge on trailheads:
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.QueryException: List has no rows for assignment to SObject
Best Answer chosen by Akshada Sonavane 2
Amit Chaudhary 8Amit Chaudhary 8
Look like you have some other tigger on account object as well. Please deactivate the same and try again

All Answers

Suraj TripathiSuraj Tripathi
Hi Akshada,

Try, this code to pass your challenge, maybe there was some little error in your code.
trigger AccountAddressTrigger on Account(before insert, before update){
	for(Account a : Trigger.new){
        if(a.Match_Billing_Address__c == true && a.BillingPostalCode!=Null){
            a.ShippingPostalCode = a.BillingPostalCode;
        }   
    } 
}​

I Hope, this will helpful to pass the challenge, if it helps you, please mark this answer as solved.
Regards
Suraj
 
Akshada Sonavane 2Akshada Sonavane 2
 my code is almost similar to this.The trigger is also invoked as I can see the changes in account record in salesforce.
Amit Chaudhary 8Amit Chaudhary 8
can you please post your code so that we can help you
Akshada Sonavane 2Akshada Sonavane 2
trigger AccountAddressTrigger on Account (before insert,before update) {

     {
        for(Account a:trigger.new)
        {
            if(a.Match_Billing_Address__c==True && a.BillingPostalCode != NULL)
            {
                a.ShippingPostalCode=a.BillingPostalCode;
            }
     }
}
}
Amit Chaudhary 8Amit Chaudhary 8
just remove the extra { } and try your code again.
trigger AccountAddressTrigger on Account (before insert,before update) {

     
        for(Account a:trigger.new)
        {
            if(a.Match_Billing_Address__c==True && a.BillingPostalCode != NULL)
            {
                a.ShippingPostalCode=a.BillingPostalCode;
            }
     }

}


 
Akshada Sonavane 2Akshada Sonavane 2
Still getting the same error..
Amit Chaudhary 8Amit Chaudhary 8
Look like you have some other tigger on account object as well. Please deactivate the same and try again
This was selected as the best answer
Akshada Sonavane 2Akshada Sonavane 2
Hi,its bcoz of the workflows and triggers which I have created on Account object,I have deactivated them and now its worked fine
Abhirup MukherjeeAbhirup Mukherjee
trigger AccountAddressTrigger on Account (before insert,before update) {
    for(Account a: Trigger.new){
        if(a.Match_Billing_Address__c==true){
            a.ShippingPostalCode=a.BillingPostalCode;
        }
    }
}
This just works fine! Hope it helps.