+ Start a Discussion
SFDCConsultant.ax449SFDCConsultant.ax449 

ConvertLead Error in Trigger

Good day,

 

I have a very simple trigger to convert leads.  We are using Person Accounts.  When I try to insert a lead here is the error I receive:

 

System.DmlException: ConvertLead failed. First exception on row 0; first error: UNAVAILABLE_RECORDTYPE_EXCEPTION, Unable to find default record type: []:

 

 

Here's the code:

trigger AutoConvertLead2 on Lead (after insert) {
    Lead thisLead = Trigger.New[0];

    Database.LeadConvert lc = new Database.LeadConvert();
    
    lc.setLeadId(thisLead.id);   
    LeadStatus convertStatus = [Select Id, MasterLabel from LeadStatus where IsConverted=true limit 1];

    lc.setConvertedStatus(convertStatus.MasterLabel);
    lc.setDoNotCreateOpportunity(true);
    
    Database.LeadConvertResult lcr = Database.ConvertLead(lc);

}

 

Any thoughts?

-Michael

hisrinuhisrinu

Seems to be for the user whoever is converting the record does not have the profile level permissions for recordtypes on create Lead/Contact/Opportunity.

 

This might be the reason user is getting this error.

chechecheche

hi SFDCConsultant, im newbie here. :|

 

have you figured why the error is showing up on convertlead? I ensured that there are default values, for Lead Contact and Opportunity as per advise of hisrinu, from my profile but still of no luck.

 

System.DmlException: ConvertLead failed. First exception on row 0; first error: UNAVAILABLE_RECORDTYPE_EXCEPTION, Unable to find default record type: [