0

Here is my apex trigger but it is unable to recognise 2 fields i.e. billingpostalcode and shippingpostalcode.

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

 //error: variable ShippingPostalCode and billingpostalcode does not exist    
}
4
  • I believe you are trying to solve the trail-head challenge. I saved the same code and it works fine. Can you share a screenshot of the whole screen. Is the API Version greater than 30.0
    – manjit5190
    Feb 19, 2016 at 7:26
  • yes API version is 36.0
    – SHR
    Feb 19, 2016 at 8:40
  • @SHR I believe there is nothing wrong with your code. Try to delete this trigger,Logout to salesforce, relogin then create it again or run this trigger from your other salesforce instance. There are some scenario where other users have some problem in trailhead even there is nothing wrong in their code.
    – Hope
    Feb 19, 2016 at 8:56
  • Have you checked the field level security on the two fields in question? Feb 19, 2016 at 9:40

1 Answer 1

-1

I tried this code and it is working on my org. Below code is based on trail-head challenge

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;
        }   
    } 

}
2
  • This doesn't answer the question and there's a bug in your code. a.Match_Billing_Address__c = true should have two == Feb 19, 2016 at 8:42
  • @Davin - OPis trying to complete a trail head challenge. I have already completed this one. So I thought this code is much helpful for him. You can see this challenge here developer.salesforce.com/trailhead/apex_triggers/… . Also I updated answer with two ==. Feb 19, 2016 at 8:59

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .