function readOnly(count){ }
Don't have an account?
Search for an answer or ask a question of the zone or Customer Support.
You need to sign in to do that
Sign in to start searching questions
Signup for a Developer Edition
Sign in to start a discussion
>> https://salesforce.stackexchange.com/questions/38/mass-lead-conversion-programmatically-or-using-data-loader
The above link has details on how to mass convert leads in apex code, please try checking it.
Let me know if it helps you and close your query by marking it as solved so that it can help others in the future.
Thanks.
I think my code may help you. Do modifications as per your requirement.
- Bulk Lead conversion with batchable class
//------------------------------------------------------------------------------------------------------------------------------------------------public class Lead_Conversion_Batch implements Database.Batchable<sObject>{
String query = 'SELECT id,Name,FirstName,LastName,Company,LeadSource,Rating,Title,IsConverted from Lead where IsConverted = false limit 1';
public Database.QueryLocator start(Database.BatchableContext BC){
System.debug('Query :: '+query);
return Database.getQueryLocator(query);
}
public void execute(Database.BatchableContext BC,List<Lead> scope){
//System.debug('Inside Execute Batch');
list<Lead> LeadsToConvert = new list<Lead>();
for(sObject lead : scope){
LeadsToConvert.add((Lead)lead);
}
System.debug(LeadsToConvert);
String convertedStatus = [SELECT MasterLabel FROM LeadStatus WHERE IsConverted = TRUE LIMIT 1].MasterLabel;
list<Database.LeadConvert> leadConverts = new list<Database.LeadConvert>();
for(Lead myLead : LeadsToConvert){
Database.LeadConvert lc = new database.LeadConvert();
lc.setLeadId(myLead.Id);
lc.setConvertedStatus(convertedStatus);
//Database.ConvertLead(lc,true);
lc.setDoNotCreateOpportunity(true);
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());
}
}
System.debug('Lead Conversion succeed');
}
public void finish(Database.BatchableContext BC){
System.debug('In Finish');
}
}
//----------Anonymous Block Execution code----
Lead_Conversion_Batch lcb = new Lead_Conversion_Batch();
// Invoke the batch job.
ID batchprocessid = Database.executeBatch(lcb);
System.debug('Returned batch process ID: ' + batchProcessId);
//---------------------------------------------------------------------------
Thanks.
https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_dml_convertLead.htm