[SalesForce] Convert lead in salesforce without creating an account

Once a lead is converted it automatically creates an account, contact and one opportunity. But in my case i want to display the result without creating an Account. Please provide me with a sample code.

Any help will be appreciated…

Best Answer

There is no way you can stop Account creation on Lead conversion. The whole point of lead conversion to create Account so as to ensure business is taking place with the customer. However, you can stop Opportunity creation. You can either create new Account on lead conversion or merge with an existing account. The steps to convert lead using apex is:

1. Instantiate LeadConvert class.
   Database.LeadConvert dl = new Database.LeadConvert();
2. There are some methods that need to be called out. Like:
   dl.setLeadId('Id of your lead');
   dl.setDoNotCreateOpportunity(Boolean);
   dl.setOwnerId(ID);
   dl.setAccountId(ID);//If you wanna merge lead with an existing account
3. Lastly you need to pass this instance to convertLead method:
   Database.LeadConvertResult result = Database.convertLead(dl);

Important Points:

  1. You can leverage this lead conversion technique in trigger or apex class.
  2. Always keep the code bulkified because convertLead() method count against your DML statements. Hence, it's better to pass a list of LeadConvert class into this method.

Hope this helps.

Related Topic