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
mukesh gupta 8mukesh gupta 8 

Trailhead Trigger chalange

Hi Expert,

I am doing Trailhead Trigger chalange :- 

User-added image
and i have create a trigger:-

trigger AccountAddressTrigger on Account (before update) {
    for(Account a : Trigger.New){
        System.assertEquals(TRUE, a.Test_LightingCo__Match_Billing_Address__c);
        a.Test_LightingCo__ShippingPostalCode__c = a.Test_LightingCo__BillingPostalCode__c ;
  }  
}
 
that is updating the shipping postal code field fine but when i click on "CHECK CHALANGE" button then got a error that is above of the image in RED.

Please suggest what i miss.

Thanks
Mukesh
 
Best Answer chosen by mukesh gupta 8
sfdcMonkey.comsfdcMonkey.com
hi Mukesh
try this below code
trigger AccountAddressTrigger on Account (before insert ,before update) {
    for(Account a: trigger.new){
        if(a.Match_Billing_Address__c && a.BillingPostalCode  != NULL)
            a.ShippingPostalCode = a.BillingPostalCode ;
    }
    
}

Thanks
Mark it best answer if it helps you

All Answers

Lalit Mistry 21Lalit Mistry 21
Hi Mukesh,

Try below code
trigger AccountAddressTrigger on Account (before update) {
    for(Account a : Trigger.New){
        if(a.Match_Billing_Address__c){
			a.Test_LightingCo__ShippingPostalCode__c = a.Test_LightingCo__BillingPostalCode__c ;
		}        
	}  
}

 
sfdcMonkey.comsfdcMonkey.com
hi Mukesh
try this below code
trigger AccountAddressTrigger on Account (before insert ,before update) {
    for(Account a: trigger.new){
        if(a.Match_Billing_Address__c && a.BillingPostalCode  != NULL)
            a.ShippingPostalCode = a.BillingPostalCode ;
    }
    
}

Thanks
Mark it best answer if it helps you
This was selected as the best answer
Amit Chaudhary 8Amit Chaudhary 8
Please check below post for same issue
1) https://developer.salesforce.com/forums/?id=906F0000000AuHoIAK
2) https://developer.salesforce.com/forums/?id=906F0000000ArVxIAK
 
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 found below issue in your code.
1) Trigger shoud be on before insert and before update event
2) You need to check Match_Billing_Address__c should be true and BillingPostalCode should not null.

Let us know if this will help you