You need to sign in to do that
Don't have an account?
Interesting Error Meeasge
I wrote the following trigger to update a set of fields.
trigger Decide_Which_Address_to_Use on SD_Member__c (before update) { For (SD_Member__c SD : Trigger.new){ // Determine if there is a bad address and which one it is. If(sd.address_bad__c==True){ If(SD.Mailing_Address__c.touppercase()==SD.Address__c.touppercase() && SD.Mailing_City__c.touppercase()==SD.City__c.touppercase()&&SD.Mailing_Zip__c==SD.Zip__c){ sd.Bad_HP_Address__c = SD.Mailing_Address__c; sd.bad_HP_City__c = sd.Mailing_city__c; sd.bad_HP_State__c = sd.mailing_state__c; sd.Bad_HP_Zip__c = SD.Mailing_Zip__c; sd.address_bad__c=False;} If(SD.Mailing_Address__c.touppercase()==SD.Pref_Address__c.touppercase() && SD.Mailing_City__c.touppercase()==SD.Pref_city__c.touppercase()&&SD.Mailing_Zip__c==SD.Pref_Zip__c){ sd.Bad_Pref_Adrs_Address__c = SD.Mailing_Address__c; sd.Bad_Pref_Adrs_City__c = sd.Mailing_city__c; sd.Bad_Pref_Adrs_State__c = sd.mailing_state__c; sd.Bad_Pref_Adrs_Zip__c = SD.Mailing_Zip__c; sd.address_bad__c=False;} If(SD.Mailing_Address__c.touppercase()==SD.NCOA_Address__c.touppercase() && SD.Mailing_City__c.touppercase()==SD.NCOA_city__c.touppercase()&&SD.Mailing_Zip__c==SD.NCOA_Zip__c){ sd.Bad_NCOA_Address__c = SD.Mailing_Address__c; sd.Bad_NCOA_City__c = sd.Mailing_city__c; sd.Bad_NCOA_State__c = sd.mailing_state__c; sd.Bad_NCOA_Zip__c = SD.Mailing_Zip__c; sd.address_bad__c=False; }} } }
And it worked fine in my sandbox.
When I moved it to production, I get the following error.
Error: Invalid Data.
Review all error messages below to correct your data.
Apex trigger Update_NCOA_Address_v01 caused an unexpected exception, contact your administrator: Update_NCOA_Address_v01: execution of AfterUpdate caused by: System.DmlException: Update failed. First exception on row 0 with id a025000000HuNUiAAN; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, Decide_Which_Address_to_Use: execution of BeforeUpdate caused by: System.NullPointerException: Attempt to de-reference a null object Trigger.Decide_Which_Address_to_Use: line 12, column 1: []: Trigger.Update_NCOA_Address_v01: line 41, column 1
So I went back in to my sandbox and change the trigger to (after Update), then I got the error in my sandbox account.
So why does Before Update, give me an error in Production and not Sandbox?
Have a look at this line
So whenever Mailing_Address__c, NCOA_Address__c,Mailing_City__c,NCOA_city__c are NULL you will get an Exception.
Place a null check before doing any operation like toUpercase
All Answers
Have a look at this line
So whenever Mailing_Address__c, NCOA_Address__c,Mailing_City__c,NCOA_city__c are NULL you will get an Exception.
Place a null check before doing any operation like toUpercase