1

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...

2 Answers 2

7

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.

0

Here you can query the account after converting the lead and delete that account. You can get the account simply by add a where clause.

select id, name from account where name= lead.company

and then delete that account.

1
  • 1
    If you do this you will erase the Contact because it's being tied to the Account.
    – Arthlete
    Commented Mar 21, 2017 at 23:03

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .