views:

24

answers:

1

Hi there, I am getting an error message when I try to instert a custom object into an exisiting 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.

regards

+2  A: 

This error means that the Lead record has been converted to a Contact. Once converted, the Lead record cannot be updated. The Lead object has an IsConverted property that you can check 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

Adam