You need to sign in to do that
Don't have an account?
Sanket 9
https://success.salesforce.com/answers?id=9063000000046HxAAI
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.
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:
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.
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:
//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()); } } } } } }
Hi Sanket,
You should make the custom label in each org with the same name and put the recordtypeid of diff org in that custom label and access it in your code.
In this way, you will get updated recordtypeId in different org.
Hope this helps.
Regards
Diksha
Thinqloud Solutions.