We are using apex to convert a lead to a person account. We are getting the following error when we do this. This code is executed on a trigger on the update of the lead. We have a custom button on the lead detailed page which on clicked would call this method using javascript.
Error message: ConvertLead failed. First exception on row 0; first error: INVALID_CROSS_REFERENCE_KEY, cannot associate a contact with a consumer account:
Code below..
Webservice static void Error(ID LeadId) {
lead l = [SELECT id,ownerId,Account_Name__c
FROM lead
WHERE id =:leadid];
Account Borrowercontactid=[SELECT id,PersonContactId
FROM Account
WHERE Id = :l.Account_Name__c limit 1 ];
id leadid1= l.id;
id accid= l.Account_Name__c;
try{
Database.LeadConvert leadConvert1 = new Database.LeadConvert();
leadConvert1.setOwnerId(l.ownerId);
leadConvert1.setLeadId(leadid1);
leadConvert1.setAccountId(accid);
leadConvert1.setContactId(null);
leadConvert1.setDoNotCreateOpportunity(true);
LeadStatus convertStatus = [SELECT Id, MasterLabel
FROM LeadStatus
WHERE IsConverted=true LIMIT 1];
leadConvert1.setConvertedStatus(convertStatus.MasterLabel);
system.debug('$$$$$$$$$$444'+ leadConvert1);
Database.LeadConvertResult lcr = Database.convertLead(leadConvert1);
}catch(Exception e){
system.debug('Exception:'+e);
}
}
Can you guys tell me what am i missing in this method? The Database.convertLead is failing at the moment..