• Srini1678
  • NEWBIE
  • 0 Points
  • Member since 2013

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 0
    Replies

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;

}
}