You need to sign in to do that
Don't have an account?
Convert list of leads which are already saved in lead sobject
I have a list of leads which i retrieve through query, now i want to convert this list of leads to account and contacts without using any trigger/validation. only through apex code. Below is code on which i am working.
list<Lead> myLead = [select id,LastName,company from Lead where company='sambodhi'];
return myLead;
for(integer i=0; i<=mylead.size();i++){
Database.LeadConvert lc = new database.LeadConvert();
lc.setLeadId(myLead[i].id);
lc.setAccountid(myLead[i].id);
LeadStatus convertStatus = [SELECT Id, MasterLabel FROM LeadStatus WHERE IsConverted=true limit 199
ALL ROWS];
lc.setConvertedStatus(convertStatus.MasterLabel);
Database.LeadConvertResult lcr = Database.convertLead(lc);
System.assert(lcr.isSuccess());
}
Try this:
All Answers
Can you explain what is the issue coming with the above code?
Thanks
first 2 lines of the code are getting executed, rest is skipped. It is not even showing any errors. The above code is to convert the list of leads i have obtained in first 2 lines.
thank you vbs, i removed return statement and my code is getting executed completely, but my condition to convert those list of leads is not getting done.
Can you confirm if the SOQL returns any data? Here are some other pointers:
1. Convert the for loop from a traditional one to a SOQL for loop for e.g.
2. The embedded SOQL in the for loop for getting a list of LeadStatus obects will throw an error for governor limits. Place it outside the loop.
3. Database leadconvert will need to be moved out of the loop as well.
Just fix these pieces and let me know if you have eny errors coming up.
The SOQL is returning list of data from sobject, i placed the embedded SOQL and database.leadconvert outside the loop, but it is returning error like unknown variable myLead.
Try this:
it's completed atlast.. thank you vbs