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
Mikhail NovozhilovMikhail Novozhilov 

UNKNOWN_EXCEPTION, java.lang.NullPointerException

Hi all,

The Lead object has some custom fields and when it's converting to a Contact I have to set the values of these fields to the custom fields of the Contact.

There are two options 1 - a new Contact and 2 - the already existing Contact.

For the second option I need to set the values only if they were not set previously (do not overwrite the previously set values)

I've created the Trigger:

trigger AACopyLeadFields on Lead (after update) {
Map<Id,Lead> leadStatus = new Map<Id,Lead>(); // Map of the converted Contact ID and the Lead Status

for(Lead lead : Trigger.new) {
if (lead.IsConverted) {
leadStatus.put(lead.ConvertedContactId,lead);
}
}

List<Contact> conContacts = new List<Contact>();

for ( Contact c : [select Id, LeadSource, CreatedDate, Converted_from_Lead__c from Contact WHERE Contact.Id IN :leadStatus.keySet()]) {
Lead lead = leadStatus.get(c.Id);
if(c.Converted_from_Lead__c == null) {
c.LeadSource = lead.LeadSource;
c.Lead_Source_Ext__c = lead.Lead_Source_Ext__c;
c.FirmwareEmail__c = lead.FirmwareEmail__c;
c.NewsletterEmail__c = lead.NewsletterEmail__c;
c.SoftwareEmail__c = lead.SoftwareEmail__c;
c.TrainingEventsEmail__c = lead.TrainingEventsEmail__c;
c.Converter_from_Lead__c = lead.Id;
conContacts.add(c);
}
}

if(conContacts.size() > 0) update conContacts;
}

When I convert a Lead into a new Contact (contact.CreatedDate == lead.LastModifiedDate) it works fine, but when I convert a Lead into already existed Contact it shows the error:

"
There was an error converting the lead. Please resolve the following error and try again: AACopyLeadFields: execution of BeforeUpdate caused by: System.DmlException: Update failed. First exception on row 0 with id 0037F00001BJtnnQAD; first error: UNKNOWN_EXCEPTION, java.lang.NullPointerException: [] Trigger.AACopyLeadFields: line 27, column 1
"

There is no any issue in the Partial Copy Sandbox.

Did someone have the same issue?



Thank you.

Regards, Michael Novozhilov
 
Abdul KhatriAbdul Khatri
Why the exception referring to BeforeUpdate failure? as I only see trigger for AfterUpdate?
Mikhail NovozhilovMikhail Novozhilov
Hi Abdul,

I've tried both before and after.

The error is the same.

Thanks.
 
Abdul KhatriAbdul Khatri
The error suggest that there a field which is not accepting null values, I meant in the field definition this check is true. Please check the line mention in the error and see it is not define like the below, if it is then make sure null is not getting pass
User-added image
Nikolay Denizhenko 8Nikolay Denizhenko 8
Hi Mikhail,

Any luck with this issue? Or you've managed to find a workaround for it?

Thanks!
Nikolai
Mikhail NovozhilovMikhail Novozhilov
Hi Nikolayi,

No. I did not fix the issue yet. We just turned the tigger off. I do nt have time to look at it as I'm too busy with another pojects.

Thanks.
Mikhail (Михаил).
Sravan Choula 19Sravan Choula 19
Hi Mikhail,

We did face the same issue updating Contact on Lead Conversion. In our scenario, we couldn't replicate this issue in any sandboxes and this was issue only in Production Org. We have reached out to Salesforce Support and they escalated this issue to thier R&D department  for resolution and they have fixed this. 

You can verify this now and if you still have this issue in your Org, I would suggest you to reach out to Salesforce Support for the fix. 

Thanks,
Sravan
Ramkumar RRamkumar R
Lead conversion sometimes runs on system context(at java layer) and might run into this null.pointer exception at the java layer. Please contact Salesforce Tech support team to enable the permission 'Enable matching in normal context for Lead convert' for your org