Skip to main content
Hi All,

I'm new to salesforce and started working on Trailhead's. I facing issue with the Trigger Challenge. Here is the triger code im writing 

trigger AccountAddressTrigger on Account (before insert) {

    for(Account a : Trigger.new){

        if(a.Match_Billing_Address__c && a.BillingPostalCode != null){

            a.ShippingPostalCode = a.BillingPostalCode;

        }

    }

    

}

but i'm getting the following error. Not sure where i'm doing wrong. can someone please help me here. Thanks in advance.

System.DmlException: Insert failed. First exception on row 0; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, TestTrigger: execution of AfterInsert caused by: System.NullPointerException: Attempt to de-reference a null object Trigger.TestTrigger: line 3, column 1: []
33 réponses
  1. 14 juin 2016, 04:38
    Hi Ranga,

    Please check the below trigger.

    trigger AccountAddressTrigger on Account (before insert,before update) {

    List<Account> acclst=new List<Account>();

    for(account a:trigger.new){

    if(a.Match_Billing_Address__c==true && a.BillingPostalCode!=null){

    a.ShippingPostalCode=a.BillingPostalCode;

    }

    }

    }

    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 de-activate all other triggers and validation rules on Account object and try again.

    Let us know if that will helps you!

    Best Regards,

    Jyothsna

     
0/9000