0

I want to use a button to quickly convert a lead into a 'Cold' account. Can I call Database.LeadConvert() then open a VisualForce page to edit a couple of Account fields but always set Lead_Rating to Cold then save the converted account?

I thought about using the standard account controller but overriding save(). Am I going about this the right way?

3 Answers 3

1

The general strategy here is to do the following:

  1. Create a custom button on Lead: Convert to Cold Account
  2. Button is attached to a VF page/controller. Use the page to enter fields that the controller getters will see.
  3. Upon Save, the Controller then executes a series of DML actions:

DML actions

  1. Update the Lead record to set Lead_Rating to Cold. This only has relevance if you map this to some Account/Contact field or ..for historical reporting on converted Leads.

  2. use convertLead(..) to convert the Lead. SFDC will map Lead fields to Contact/Account. You'll makes sure to not create an Opportunity by using isDoNotCreateOpportunity(true). LeadConvertResult.getAccountId() will let you know the convertedToAccountId and you can then update that Account with the properties you collected from the user in step 2. (Alternatively, you can use custom Lead fields to capture the properties in step 2 and have SFDC Lead mapping place them in the Account.)

2
  • Thanks. This has clarified things for me. I'll make progress and report back.
    – Dizzley
    Jul 4, 2016 at 12:41
  • Thanks, that was very helpful. Marked answer as correct.
    – Dizzley
    Jul 6, 2016 at 13:13
0

You could create a field on the Lead object with value "Cold" and map it

create the field on the lead (use standardvalue or whatever to set the value of Cold). go to: Setup > Customize > Leads > Fields > Lead Custom Fields & Relationships > Press: Map Lead Fields

and map the field to the Lead_Rating field

2
  • I don't want every Lead to be rated 'Cold' but I want to rate some of them programmatically. I would have thought it possible to write a controller extension to update the Account field on Save.
    – Dizzley
    Jul 1, 2016 at 13:12
  • In the Controller extension, can I not update fields in the record in context? Account ac = (Account)stdController.getRecord(); ac.Lead_Rating__c = 'Cold'; ... save();
    – Dizzley
    Jul 1, 2016 at 13:19
0

You can use can use Database.LeadConvert() wherein you can supply the account id that you want to select. For updating the account you will have to do it as a separate update DML on account.

      Database.LeadConvert convLead = new database.LeadConvert();
      convLead .setLeadId(Lea.Id);
      convLead .setAccountId(acc.Id);
      convLead.setConvertedStatus('ClosedConverted');
      convLead .setDoNotCreateOpportunity(true);           
      Database.LeadConvertResult[] LeaConvResults = Database.convertLead(leadCollectionArray,false);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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