Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Salesforce by (11.9k points)

I am getting an error message when I try to insert a custom object into an existing lead object.

List<Lead> leads =[select Id from Lead where Email =:lead.Email ];
if(leads.size()>0)
{
    Lead existing_lead = new Lead(Id = leads[0].id);
    social_account.Lead__c = existing_lead.Id; //social_account is a custom object that
                                               //has a child relationship to lead.
                                               //ie lead is a parent of social_accounts.
    update existing_lead;
    insert social_account; //if there is an existing lead with same same email,
                           //i'd like to insert new social_account to an exsiting lead.
}

I am getting this error:

554 System.DmlException: Update failed. First exception on row 0 with id 00Q3000000WW3isEAD; first error: CANNOT_UPDATE_CONVERTED_LEAD, cannot reference converted lead: []

Class.ProcessContact.handleInboundEmail: line 81, column 9 External entry point

even if I comment out the 'update existing_lead', i get a similar error message.

554 System.DmlException: Insert failed. First exception on row 0; first error: CANNOT_UPDATE_CONVERTED_LEAD, cannot reference converted lead: [Lead__c]

Class.ProcessContact.handleInboundEmail: line 82, column 9 External entry point

I would appreciate any suggestions.

1 Answer

0 votes
by (32.1k points)

So basically, this error indicates that the Lead record has been transformed to a Contact. Once converted, the Lead record can't be modernized. The Lead object has an IsConverted property that you can compare to see if it has been converted. If IsConverted is true, ConvertedContactId will hold the contact ID of the new Contact record.

Lead Object reference

Browse Categories

...