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
Swami DeshanelSwami Deshanel 

Attachments on Leads Causing Autoconvert Trigger to fail

I have an autoconvert trigger that will convert a lead when a checkbox is checked.  It works fine both one record at a time and in bulk except when the lead has an attachemnt and I cant figure out why.

Here is my code

trigger AutoConvert on Lead (after update) {
    list<Lead> LeadsToConvert = new list<Lead>();
    for(Lead myLead: Trigger.new){
        if((!myLead.isConverted)
        && myLead.To_Be_Converted__c== True) {
        LeadsToConvert.add(myLead);
    }
}

    list<Database.LeadConvert> leadConverts = new list<Database.LeadConvert>();
    for(Lead myLead : LeadsToConvert){
        Database.LeadConvert lc = new database.LeadConvert();
        lc.setLeadId(myLead.Id);
        lc.convertedStatus = 'Consult to be Scheduled';
        //Database.ConvertLead(lc,true);
        lc.setDoNotCreateOpportunity(False);
        leadConverts.add(lc);
    }

    if(!leadConverts.isEmpty()){
        for(Integer i = 0; i <= leadConverts.size()/100 ; i++){
            list<Database.LeadConvert> tempList = new list<Database.LeadConvert>();
            Integer startIndex = i*100;
            Integer endIndex = ((startIndex+100) < leadConverts.size()) ? startIndex+100: leadConverts.size();
            for(Integer j=startIndex;j<endIndex;j++){
                tempList.add(leadConverts[j]);
            }
            Database.LeadConvertResult[] lcrList = Database.convertLead(tempList, false);
            for(Database.LeadConvertResult lcr : lcrList)
                System.assert(lcr.isSuccess());
        }
    }
}
EnreecoEnreeco
Which is the error thrown?