• mohand talbi
  • NEWBIE
  • 0 Points
  • Member since 2020

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

Hi I have the trigger below to populate a child field from a parent object field. Upon firing the trigger gives a NULL Pointer error. I have tried severally to for a solution to it but to no avail. Could someone help me with an explanation as to why the error and suggestion to a solution. Thanks.

 

 

trigger populateFieldOnCase on Case (before insert){

Set<id>parentIds = new Set<id>();

for(Case acase:trigger.new){

parentIds.add(acase.project__c);
}
Map<id,parent__c> pro = new Map<id,parentt__c>([select id,parentField__c from parent__c where id in :parentIds]);

for(case acase:trigger.new){

acase.childfield__c = pro.get(acase.id).parentField__c;

}
}

  • August 26, 2013
  • Like
  • 0