0

Business requirement is to convert 1000 leads which are owned by a user, I heard that we can right a adhoc Apex code in anonymous Window and execute it to convert.

Can any one help me in providing the code, which convert leads owned by a particular user.

  • 1
    Hi Harry, welcome to Salesforce Stack Exchange. Have you had a chance to look at How to Ask? One of the things we look for is details about your issue and what code you've written or research you've done to solve the problem, so we can provide a specific answer. SFSE isn't a code-writing service as such. – David Reed May 22 '18 at 1:19
  • @DavidReed Who'd have thought this was actually a duplicate? – sfdcfox May 22 '18 at 1:39
0

You're going to want to read more about Database.LeadConvert and the SOQL/SOSL Reference Guide before attempting to run this code.


⚠️ DO NOT RUN THIS CODE WITHOUT UNDERSTANDING THE CONSEQUENCES ⚠️


At an absolute minimum, the following code will bulk convert leads, 1000 at a time:

Database.LeadConvert[] converts = new Database.LeadConvert[0];
LeadStatus convertedStatus = [SELECT MasterLabel FROM LeadStatus WHERE IsConverted = true LIMIT 1];
for(Lead record: [SELECT Id FROM Lead WHERE IsConverted = false LIMIT 1000]) { 
    Database.LeadConvert convert = new Database.LeadConvert();
    convert.setLeadId(record.Id); 
    convert.setConvertedStatus(convertedStatus.MasterLabel);
    converts.add(convert);
}
Database.convertLead(converts);

Not the answer you're looking for? Browse other questions tagged or ask your own question.