• cheche
  • NEWBIE
  • 0 Points
  • Member since 2012

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
    Questions
  • 4
    Replies

Hai All,

 

When i am converting a lead Its giving Error

Error: ConvertLead Failed: First exception on row 0; First error: UNAVAILABLE_RECORDTYPE_EXCEPTION,unable to find defaultnrecord type[]

 

Below is the Class code On convert lead

// This class is meant to hold all the code which will be reusable and common processes. Some webservice methods we can write here also.

global class Lead_Manager
{
    // Responsible for lead conversion from standard page layout.
    // Below webservice method is being called on the click event of the custom convert button on the standard lead page layout.
    WebService static String convertLeadByConvertCustomeButton(String leadId)
    {
        try
        {
            Lead led = [Select id,Name,Status,LeadSource ,IsConverted ,(Select id,ContentType,Name,LastModifiedDate from Attachments) from Lead where id = :leadId];
            if(led.Attachments.size()==0)
                return 'Please upload documents before converting the lead.';
            if(led.Status=='Approved')
            {

             // Here it is throwing Error
                Database.LeadConvert lc = new database.LeadConvert();
                lc.setLeadId(leadId);
                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);
                //ApexPages.addMessage(new ApexPages.message(ApexPages.severity.confirm,'Lead has been converted successfully.'));
                led = [Select id,Name,Status,LeadSource ,IsConverted ,ConvertedAccountId,ConvertedContactId from Lead where id = :leadId];
                /* List<Contact> contactList = [Select id from Contact where id=:led.ConvertedContactId];  
                if(contactList.size()>0)
                    delete contactList; */
                return String.ValueOf(led.ConvertedAccountId);
            }
            else
                return 'CSR has not approved the lead so it can not be converted.';
            
        }
        catch(System.Exception e)
        {
            return e.getMessage();
        }
    }
 
    //Lead conversion custom method. This method will take an instance of Lead object
    //and will convert it without creating opportunities and returned the converted lead to its caller.
    // Responsible for lead conversion from visual force.
    public static Lead convertLead(Lead lead)
    {
        Database.LeadConvert lc = new database.LeadConvert();
        lc.setLeadId(lead.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);
        Lead led = [Select id,Status,LeadSource ,ConvertedAccountId,RecordType.Name,Name,OwnerId,CreatedById,FirstName,LastName,Street,City,State,PostalCode,Email,phone,Last_4_digits_SSN__c,Date_of_Birth__c,IsConverted,
                            Enrollment_Id__c,EBT_Number__c,EBT_Holder__c,Number_of_Persons_or_Household__c,Monthly_Income__c,Yearly_Income__c
                            from Lead
                            where id = :lead.id];
       return led;
    }
 
 
    @RemoteAction
    global static String checkLeadApprovalStatusByCSR(String leadId)
    {
        Lead lead = [Select id,Status from Lead where id = :leadId];
        if(lead.Status == 'Approved')
            return '1';
        else
            return '0';
    }
 
}

Hi 

 

I have stucked to convert lead to person aaccount via web to lead process (Lead is convert while in insertion only ) . 

 

I am able to convert lead to account , contact & opportunity. 

 

So can any one help on this ..

I do have a test class, when I run the test i got this error:

 

 

System.DmlException: ConvertLead failed. First exception on row 0; first error: UNAVAILABLE_RECORDTYPE_EXCEPTION, Unable to find default record type: []Class.TestTriggerAreaUpdate.TestReferralUpdate: line 20, column 38 External entry point

 

 

How do I specify the Account record type in the TestClass?....or i missed it in the trigger.....is a person account (just in case that helps)

Thank you

 

 

@isTest
//This is a test case for a situation where a lead will be converted.  The developer must explicitly call the convert lead
//method to simulate the user action.

private class TestTriggerAreaUpdate {
        static testMethod void TestReferralUpdate() {
        // Insert the Lead
        List<Lead> leads = new List<Lead>();
        Lead leadt = new Lead (FirstName ='fname', LastName ='test', Company ='myCompany');
        insert leadt;
        // Insert the custom object Record 
        reas_de_Inter_s__c Area = new reas_de_Inter_s__c (Lead__c = leadt.Id);
        insert Area;    
    
    //Convert the Lead
    Database.LeadConvert lc = new database.LeadConvert();
    lc.setLeadId(leadt.Id);
    LeadStatus convertStatus = [Select Id, MasterLabel from LeadStatus where IsConverted=true limit 1];
    lc.setConvertedStatus(convertStatus.MasterLabel);
    Database.LeadConvertResult lcr = Database.convertLead(lc);    
    
    //Requery for the referral record to see if it is updated
    reas_de_Inter_s__c ref_upd = [select Account__c from reas_de_Inter_s__c where Lead__c = :leadt.Id];
        
    //Check that the test passed
        System.assertEquals(ref_upd.Account__c,[Select ConvertedAccountId From Lead Where Id = :Area.Lead__c].ConvertedAccountId);
              
  
    //Test if no opty is created
    string NoOpty = 'Y';    
    if (NoOpty =='Y'){
      Lead leadto = new Lead (FirstName ='fnameo', LastName ='testo', Company ='myCompanyo');
          insert leadto;
          // Insert the custom object record 
          reas_de_Inter_s__c Areao = new reas_de_Inter_s__c (Lead__c = leadto.Id);
          insert Areao;
      
      Database.LeadConvert lco = new database.LeadConvert();
      lco.setLeadId(leadto.Id);
      lco.isDoNotCreateOpportunity();
      lco.setDoNotCreateOpportunity(true);
      LeadStatus convertStatuso = [Select Id, MasterLabel from LeadStatus where IsConverted=true limit 1];
      lco.setConvertedStatus(convertStatuso.MasterLabel);
      Database.LeadConvertResult lcro = Database.convertLead(lco); 
    
      reas_de_Inter_s__c ref_updo = [select Account__c from reas_de_Inter_s__c where Lead__c = :leadto.Id];
      
      //Check that the test passed
          System.assertEquals(ref_updo.Account__c,[Select ConvertedAccountId From Lead Where Id = :Areao.Lead__c].ConvertedAccountId);
 
    }  
    }

 

  • September 14, 2011
  • Like
  • 0

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