You need to sign in to do that
Don't have an account?

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 : []
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 : []
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