
I have a trigger that converts all the lead with same website and one of these is converted manually.
Here is the code :
trigger automaticConvertLeads on Lead (after update) {
//Set the status of Converted Lead
LeadStatus convertStatus = [
select MasterLabel
from LeadStatus
where IsConverted = true
limit 1
];
list<lead> LeadsToConvert = new list<lead>();
for (Lead L : Trigger.new){
//If lead has been converted from the UI not through trigger
string web = L.website;
if(L.isconverted && L.Converted_From_Trigger__c == FALSE && !(string.ISBLANK(web))){
//If lead has been converted , fetch the Account Name
List <lead> AllLeads = [select id,company, name,ConvertedAccountId,email,isconverted from Lead where isConverted = false AND website =:web];
//List of email that needs to be converted
for (Lead LTC : AllLeads){
LTC.Converted_From_Trigger__c = TRUE;
LeadsToConvert.add(LTC);
}
}
system.debug('leads to be converted' + LeadsToConvert);
//updating the checkbox so that this trigger does not fire again
update LeadsToConvert;
//Loop for Converting the leads
for (lead le : LeadsToConvert) {
Database.LeadConvert lc = new Database.LeadConvert();
lc.setLeadId(le.Id);
lc.setAccountId(L.ConvertedAccountId);
lc.setConvertedStatus(convertStatus.MasterLabel);
lc.setDoNotCreateOpportunity(TRUE);
database.LeadConvertResult lcr = Database.convertLead(lc);
}
}
}
we have 90-100 leads from same website. and I am getting error frequently "Unknown Exception" but not able to figure out in debug logs which one is giving error. How can i identify which one is giving error
5 risposte
Next step to debug - Take the extract of the lead , contact, Account record which is converted manually through UI.
And validate your logic in code if you have taken care of all the fields while converting through code.
Check for restricted picklist values etc..
Also you need access on account linked to the contact before you can convert the respective lead since internallty salesforce updates some values on account as well.