function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Sanket 9Sanket 9 

ConvertLead failed. First exception on row 0; first error: UNAVAILABLE RECORDTYPE EXCEPTION, Unable to find default record type

Hi All,

I have a custom object named Payment, which has look up to Lead. On Payment page, I have a button to call Apex class, which changes Lead status which in turn results in after update lead trigger that converts lead using  Database.convertLead() method.
I am having System Administrator profile, but I am getting error as ConvertLead failed. First exception on row 0; first error: UNAVAILABLE RECORDTYPE EXCEPTION, Unable to find default record type

Note: I just created new sandbox, and this function has stopped working on new sandbox. Same functionality is working on Production. My profile has default record type assigned for Account, which is common answer found for this issue. But that is already in place and issue still persists. Convert Lead option is also enabled for me.

Lead, Opportunity do not have record types and there is no custom field vaidation exception shown in debug log.

Any help is highly appreciated.

Approval Page Error on Payment details page:
User-added image
 
//Code for class called from Payment detail page button: 

global class nmLeadWebService 
{
    //New method for Approve registration by IC
    webService static string ApproveRegistrationNew(String strLeadId) 
    {
         Lead objLead = new Lead(id=strLeadId);
         objLead.nm_LeadContacted__c = 'Yes'; 
         
         update objLead;
        
         objLead.nm_PaymentCompleted__c = true;
         
         update objLead;
       
         objLead = [select id, ConvertedAccountId, convertedOpportunityId from Lead where id =: strLeadId];
        
         //Code to transfer registration payment record to opportunity from lead
         List<nm_Payment__c> lstPayment = [select id, nm_OpportunityNew__c from nm_Payment__c where nm_Lead__c =: strLeadId and nm_PaymentStatus__c='Payment Made'];
         if(lstPayment != null && lstPayment.size() > 0)
         {
            for(nm_Payment__c objPayment : lstPayment)
            {
                       
                objPayment.nm_Lead__c = null;
                objPayment.nm_OpportunityNew__c = objLead.ConvertedOpportunityId;               
            }
            
            update lstPayment;
         }
         system.debug('Done');
         return objLead.ConvertedAccountId;
    }

//Code in Lead Trigger handler class
//Method to convert lead once Registration payments completed
    public void ConvertLead(list<Lead> lstLead, map<id, Lead> leadOldMap)
    {
        if(lstLead != null && lstLead.size() > 0)
        {
            set<string> strDuplicate = new set<string>();
            //Adding Email MobilePhone in set in string format 
            for(Lead objLead : lstLead)
            {
                strDuplicate.add(((String)objLead.Email + (String) objLead.MobilePhone ).toLowerCase());
                System.debug('**strDuplicate'+strDuplicate);
            }
            
            //getting accounts already in Account
            list<Account> lstAccount = [select id,(select id from Contacts limit 1), 
                                        nm_CheckDuplicate__c from Account
                                         where nm_CheckDuplicate__c in : strDuplicate];
            System.debug('**lst account'+lstAccount);
            map<string, Account> mapDupAccounts = new map<string, Account>();
            for(Account objAccount : lstAccount)
            {
                mapDupAccounts.put(objAccount.nm_CheckDuplicate__c, objAccount);
            }
            LeadStatus convertStatus = [SELECT Id, MasterLabel FROM LeadStatus WHERE IsConverted=true LIMIT 1];
            for(Lead objLead : lstLead)
            {
                //Checking is registration payment done
                if(objLead.nm_Program__c != null && objLead.nm_EligiblityCriteria__c != null && objLead.nm_PaymentCompleted__c == true && leadOldMap.get(objLead.id).nm_PaymentCompleted__c == false)
                {
                    string strLead = ((String)objLead.Email + (String) objLead.MobilePhone ).toLowerCase();
                    if(mapDupAccounts.get(strLead) != null)
                    {
                        Database.LeadConvert lc = new Database.LeadConvert();
                        
                        lc.setLeadId(objLead.id);
                        lc.setAccountId(mapDupAccounts.get(strLead).id);
                        
                        lc.setContactId(mapDupAccounts.get(strLead).Contacts[0].id);
                        
                        
                        lc.setConvertedStatus(convertStatus.MasterLabel);
                        
                        try{
                            Database.LeadConvertResult lcr = Database.convertLead(lc);
                        }
                        catch(exception ex)
                        {
                            objLead.addError(ex.getMessage()); 
                        }
                    }
                    
                    else
                    {
                        Database.LeadConvert lc = new Database.LeadConvert();
                        
                        lc.setLeadId(objLead.id);
                        
                       // LeadStatus convertStatus = [SELECT Id, MasterLabel FROM LeadStatus WHERE IsConverted=true LIMIT 1];
                        lc.setConvertedStatus(convertStatus.MasterLabel);
                        
                        try{
                            Database.LeadConvertResult lcr = Database.convertLead(lc);
                        }
                        catch(exception ex)
                        {
                            objLead.addError(ex.getMessage());
                        }
                    }                   
                }
            }
        }
    }

 
KalyanGKalyanG
@Sanket, Did you get any work around this issue?