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
anil87anil87 

Mass lead converter

Hi Everyone,
 
We'd like to convert multiple leads into Multiple Person Account & Opportunities. They should also be assigned the correct name. 
ex: Lead Name: Marc benioff could be converted into a Person account with the name of Marc benioff and Opp name of Marc benioff.
i came across "Mass Lead Converter by Force.com Labs" it has a limitation of  100 records for click i need to overcome this too..Any help greatly apreciated..

 

Vinit_KumarVinit_Kumar

Try to create a Trigge to handle the same,the Trigger would run on update event of Lead.Please find below the code for your reference :-

 

trigger LeadConvert on Lead (after update) {

List<Account> accList = new List<Account>();
List<Contact> conList = new List<Contact>();
List<Opportunity> oppList = new List<Opportunity>();

//Bulkified
for (Lead lead : Trigger.new) {
if (lead.isConverted == false) //to prevent recursion
{

Database.LeadConvert lc = new Database.LeadConvert();
lc.setLeadId(lead.Id);

LeadStatus convertStatus = [SELECT Id, MasterLabel FROM LeadStatus WHERE IsConverted=true LIMIT 1];
lc.setConvertedStatus(convertStatus.MasterLabel);


Database.LeadConvertResult lcr = Database.convertLead(lc);
System.assert(lcr.isSuccess());


Account acc = new Account(id=lcr.AccountId,Roll_No__c=lead.Roll_No__c);
accList.add(acc);

Contact con = new Contact(id=lcr.ContactId,Roll_No__c=lead.Roll_No__c);
conList.add(con);

Opportunity opp = new Opportunity(id=lcr.OpportunityId,Roll_No__c=lead.Roll_No__c);
oppList.add(opp);

}
}

update accList;
update conList
update oppList;
}