function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Bethann Gonzalez 6Bethann Gonzalez 6 

Error Converting Lead - Duplicate Contact- Contact Trigger + Process Builder

Hi All,

I created a process builder that would create additional contacts capture on a lead record when the lead is converted. 

However when the user converts the lead, they recieve the following error message:

There was an error converting the lead. Please resolve the following error and try again: We can't save this record because the “Higher Ed - Additional Contact Creation on Lead Conversion” process failed. Give your Salesforce admin these details. This error occurred when the flow tried to create records: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY: ContactTrigger: execution of BeforeInsert caused by: System.NullPointerException: Attempt to de-reference a null object Class.methods_Contact.checkContactDupe: line 419, column 1 Class.th_Contact.OnBeforeInsert: line 95, column 1 Trigger.ContactTrigger: line 27, column 1. You can look up ExceptionCode values in the SOAP API Developer Guide. Error ID: 572035254-126199 (-482495930)ok up ExceptionCode values in the SOAP API Developer Guide. Error ID: 572035254-126199 (-482495930)

I'm not what do. The user still needs to convert the lead. If there is additional contact that is duplicate, we want the system to use the existing contact record. Is there a way to do this in the process builder so it wouldn't cause an error with the Contact Trigger?

User-added image
Rakshana Cube84Rakshana Cube84
Hello Bethann,

It seems Attempt to de-reference a null object error that will appear when you are trying to access a variable that is null(no data) in the code. It's better to share the code to verify. 

Thanks,
Rakshana
Bethann Gonzalez 6Bethann Gonzalez 6
Thank you Rakshana for responding. Here is the Contract Trigger Code.

 
//==================================================================================================
//  Object: Contact Trigger
// Comment: Contact Trigger
//==================================================================================================
//          Date            Purpose
// Changes: 06/14/2018      Initial Version
//                          NOTE:  THERE IS AN EXISTING CONTACT BEFORE TRIGGER I AM NOT UPDATING.
//          12/15/2018      Adding logic for QSCId to populate Account
//==================================================================================================

trigger ContactTrigger on Contact (   after delete, after insert, after undelete, 
                                      after update, before delete, before insert, 
                                      before update) {

    //Trigger Handler
    th_Contact handler = new th_Contact(trigger.isExecuting, trigger.size);    
                                          
    //After Update
    if(trigger.isAfter && trigger.isUpdate){
        handler.OnAfterUpdate(trigger.old, trigger.new, trigger.oldMap, trigger.newMap);
    } 

    //Before Insert                                          
    if(trigger.isBefore && trigger.isInsert){
        handler.OnBeforeInsert(trigger.new, trigger.newMap);  
        
        Set<Id> AccountIds = new Set<Id>();
        
        for(Contact cu5: trigger.new) {
				 
				 if(cu5.Status__c == 'Active' || cu5.Status__c == null){
					 
					 cu5.Active_Lookup__c = cu5.AccountId;
					 cu5.Inactive_Lookup__c = null;
					 
					 
				 }else{
                     
					 cu5.Inactive_Lookup__c = cu5.AccountId;
					  cu5.Active_Lookup__c = null;
				 }
            
            AccountIds.add(cu5.AccountId);
    }
        
         for(Contact cu5: trigger.new) {
				 
             for(Account acc : [Select id, name, Synced_Contact__c, Synced_Contact__r.Status__c from Account where id in: AccountIds ]){
                 
                 if(cu5.Name == acc.Name){
                    
                      if(acc.Synced_Contact__r.Status__c == 'Active' || acc.Synced_Contact__r.Status__c == null){
					 
					 cu5.Active_Lookup__c = cu5.Id;
					 cu5.Inactive_Lookup__c = null;
					 
					 
				 }else{
                     
					 cu5.Inactive_Lookup__c = cu5.Id;
					  cu5.Active_Lookup__c = null;
				 }
                     
                     
                     
                 }
                 
                 }
        
    } 
    }
                                          
	//After Insert                                          
    if(trigger.isAfter && trigger.isInsert){
        handler.OnAfterInsert( trigger.newMap);     
    }
        

    //Before Update                                          
    if(trigger.isBefore && trigger.isUpdate){
        handler.OnBeforeUpdate(trigger.new, trigger.oldMap, trigger.newMap); 
        
         for(Contact cu5: trigger.new) {
				 
				 if(cu5.Status__c == 'Active' || cu5.Status__c == null){
					 
					 cu5.Active_Lookup__c = cu5.AccountId;
					 cu5.Inactive_Lookup__c = null;
					 
					 
				 }else{
                     
					 cu5.Inactive_Lookup__c = cu5.AccountId;
					  cu5.Active_Lookup__c = null;
				 }
				 
             
             
             
				 
			 }
    }
    
}