You need to sign in to do that
Don't have an account?
Mikhail 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) {
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
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) {
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()]) {
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) {
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);
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;
}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
I've tried both before and after.
The error is the same.
Thanks.
Any luck with this issue? Or you've managed to find a workaround for it?
Thanks!
Nikolai
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 (Михаил).
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