• Laura Ryan
  • NEWBIE
  • 0 Points
  • Member since 2015

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 0
    Replies
When attempting to convert a Lead to an Opportunity, our LeadConvert class is throwing the same exception every 2-3 hours. The exception is thrown from the convertLeads method.

Is there any way we can kill the process that's throwing the exceptions? Any test conversions we've done succeed so it looks like it's the same one trying and failing every 2-3 hours.

The exception email says:
 
Apex script unhandled trigger exception by user/organization: 005200000033tk4/00D20000000Cl2i
 
LeadConverter: execution of AfterInsert
 
caused by: System.DmlException: ConvertLead failed. First exception on row 0; first error: FIELD_CUSTOM_VALIDATION_EXCEPTION, Validation error on Opportunity: If the Lead is to be converted ... please set a Lead Source: []
 
Trigger.LeadConverter: line 44, column 1
and the LeadConverter class is
Trigger LeadConverter on Lead (after insert) 
{

    // Get String for 'Converted'
    LeadStatus convertStatus = [
        select MasterLabel
        from LeadStatus
        where IsConverted = true
        limit 1
    ];
    
    // Get Automated Lead RecordTypeId
    RecordType leadRt = [
        Select id 
        From RecordType
        where developername='Automated_Lead'
        limit 1
    ];
    
    List<Database.LeadConvert> leadConverts = new List<Database.LeadConvert>();
    
    for (Lead lead: Trigger.new) 
    {
    
      // For each unconverted Automated Lead
      if (!lead.isConverted && lead.RecordTypeId == leadRt.id) 
      {
      
        Database.LeadConvert lc = new Database.LeadConvert();
               
        lc.setLeadId(lead.Id);
        lc.setOpportunityName(lead.Name);
        lc.setConvertedStatus(convertStatus.MasterLabel);
               
        leadConverts.add(lc);

      }
    }
 
    if (!leadConverts.isEmpty())
    {
      List<Database.LeadConvertResult> lcr = Database.convertLead(leadConverts);
    }
}
The Validation Rule referenced in the email is
AND(  IsConverted = True,  LEN(TEXT(LeadSource))=0 )
Any help much appreciated!