You need to sign in to do that
Don't have an account?
APEX Code Verification
I have written below APEX trigger to update contact address whenever contact account is changed. Code is working but when i am using data loader to update other fields they are not updating and getting this error; i am trying to update a field which is not used in trigger. Any help will great, thanks in advace
Error
------
CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY:UpdMailingAddress: execution of BeforeUpdate
caused by: System.NullPointerException: Attempt to de-reference a null object
Trigger.UpdMailingAddress: line 17, column 1
Trigger
----------
trigger UpdMailingAddress on Contact (before update)
{
Set<Id> parentIds = new Set<Id>();
for(contact c : trigger.new)
{
parentids.add(c.accountid);
}
map<id, account> accountid = new map<id, account>();
accountid.putall([select Id,billingCity,billingCountry, billingPostalCode,billingState, billingStreet from account where id in :parentIds]);
for(contact c:trigger.new)
{
c.mailingcity=accountid.get(c.accountid).billingCity;
c.mailingCountry=accountid.get(c.accountid).billingCountry;
c.mailingPostalCode=accountid.get(c.accountid).billingPostalCode;
c.mailingState=accountid.get(c.accountid).billingState;
c.mailingStreet=accountid.get(c.accountid).billingStreet;
}
}
the billingStreet field must not be having any value. Please try to add a value and then check if it works else try to write a null check in the code