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
jitender.360degreec1.3890927586840896E12jitender.360degreec1.3890927586840896E12 

Error when trying to Convert a Lead

Hi,

i write an trigger on lead for Lead Conversion based on some conditions.

In that trigger i am getting below error

Error: Invalid Data.
Review all error messages below to correct your data.
Apex trigger tg_ConvertLead caused an unexpected exception, contact your administrator: tg_ConvertLead: execution of AfterInsert caused by: System.DmlException: ConvertLead failed. First exception on row 0; first error: UNKNOWN_EXCEPTION, System.DmlException: Insert failed. First exception on row 0; first error: UNKNOWN_EXCEPTION, externalized text label not found, section: 'udd_HotOrganization' missing: [] (System Code) : []: Trigger.tg_ConvertLead: line 41, column 1

can anyone help me with the same....

thanks in advance...


jitender.360degreec1.3890927586840896E12jitender.360degreec1.3890927586840896E12
My trigger code is below :

trigger tg_ConvertLead on Lead (after insert,after update) {
list<opportunity>opplist = new list<opportunity>();

List<Database.LeadConvert> leadConverts = new List<Database.LeadConvert>();
//Database.LeadConvert lc = new Database.LeadConvert();

List<LeadStatus> convertedLeadStatuses = [SELECT Id, MasterLabel FROM LeadStatus WHERE IsConverted=true LIMIT 1];
Map<Id, String> leadstatuses = new Map<Id, String>();

    for(LeadStatus ls : convertedLeadStatuses)
    {
       leadstatuses.put(ls.Id, ls.MasterLabel);
    }


for (Lead nl : Trigger.new)
{
if(nl.isConverted == false) //to prevent recursion &&(nl.Appointment__c!=null)
{

    Database.LeadConvert lc = new Database.LeadConvert();
        lc.setLeadId(nl.id);
       // lc.setOverwriteLeadSource(false);
       lc.setDoNotCreateOpportunity(false);
       lc.setConvertedStatus(convertedLeadStatuses[0].MasterLabel);

        // Check to see if account already exists
       /* if(!peAccounts.isEmpty()){
            if(peAccountsFlipped.get(nl.email)!=null){
                lc.setAccountId(peAccountsFlipped.get(nl.email));
                lc.setOwnerId(peAccountsOwner.get(peAccountsFlipped.get(nl.email)));
                lc.setDoNotCreateOpportunity(true);
            }   
        } else {
         */   // In the event an account doesn't exist
           // lc.setOwnerId('005G000000402QS');
           
           // lc.setOpportunityName(nl.Name);
       // }
        //leadConverts.add(lc);
        Database.LeadConvertResult lcr = Database.convertLead(lc);
        system.debug('++++++++++lcr'+lcr);
   
}  
}
//Database.LeadConvertResult lcr = Database.convertLead(leadConverts);

//Database.convertLead(leadConverts);
/*for(Database.LeadConvertResult lcs:lcr)
{
        if(lcs.issuccess())
        {
             opportunity opp = new opportunity();
             opp.id = lcs.getopportunityid();  
             opp.stagename = 'Appointment Booked';
             opp.CloseDate = date.today()+90;
             opp.AccountId = lcs.getAccountId();
             opplist.add(opp);
        }
}       
if(opplist.size()>0)
{
    update opplist;
}*/
}
RishavRishav
HI ,
if ( trigger.isAfter && trigger.isInsert)
    {
    	for( Lead l : trigger.new)
    	{
    		if(  l.IsConverted == false)
            {
            	Database.Leadconvert lc = new Database.LeadConvert();
            	
            	lc.setLeadId(l.Id);
            	lc.setDoNotCreateOpportunity(true);
            	LeadStatus convertStatus = [SELECT Id, MasterLabel FROM LeadStatus WHERE IsConverted=true LIMIT 1];
            	lc.setConvertedStatus(convertStatus.MasterLabel);
            	
            	Database.Leadconvertresult lcr = Database.convertLead(lc);
            	System.assert(lcr.isSuccess());
            	
            	Account newA = new Account( id = l.ConvertedAccountId, Primary_Contact__c = l.ConvertedContactId, Name = l.FirstName + ' ' + l.LastName);
            	//UpdateAccts.add(newA);
            	insert newA;
            }
    	}
    	//Insert UpdateAccts;
    }


Tony_420Tony_420
I think you are missing some required field on Account or Contact which is stopping your lead to get converted and Create Account and Contact. Please Check all the required fields and map them.