• dvid1.3963852481454365E12
  • NEWBIE
  • 0 Points
  • Member since 2014

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 1
    Replies
Here's the situation - I have a custom object (Referral__c) with a lookup(account) field to (Client__c). That Account has a lookup(contact) field that I want placed into the record on the custom object, field is called Internal_Referral_By__c. I believe I may need to check that the lookup(contact) is not null, but I haven't got there yet. Here's where I am and am getting "Attempt to de-reference a null object" errorsL


trigger autoPopulateReferredBy on Referral__c (before insert, before update){

      set<Id> clientIDSet = new set<Id>();
    for(Referral__c referral: trigger.new){
        if(referral.Client__c != null){
            clientIdSet.add(referral.Client__c);
        }
    }

     map<id, Account> acctMap = new map<ID, Account>([SELECT Id, Name FROM Account where Id IN: clientIdSet]);


    for(Referral__c referral: trigger.new){
        if(acctMap.containsKey(referral.Client__c)){
            referral.Internal_Referral_By__c = acctMap.get(referral.Id).Internal_Referral_By__c;
        }      
    }

}
Here's the situation - I have a custom object (Referral__c) with a lookup(account) field to (Client__c). That Account has a lookup(contact) field that I want placed into the record on the custom object, field is called Internal_Referral_By__c. I believe I may need to check that the lookup(contact) is not null, but I haven't got there yet. Here's where I am and am getting "Attempt to de-reference a null object" errorsL


trigger autoPopulateReferredBy on Referral__c (before insert, before update){

      set<Id> clientIDSet = new set<Id>();
    for(Referral__c referral: trigger.new){
        if(referral.Client__c != null){
            clientIdSet.add(referral.Client__c);
        }
    }

     map<id, Account> acctMap = new map<ID, Account>([SELECT Id, Name FROM Account where Id IN: clientIdSet]);


    for(Referral__c referral: trigger.new){
        if(acctMap.containsKey(referral.Client__c)){
            referral.Internal_Referral_By__c = acctMap.get(referral.Id).Internal_Referral_By__c;
        }      
    }

}