I'm trying to convert leads, but I am having trouble when it creates opportunities. My opportunities have lookup fields that I would really like to auto populate (and be required).

I can't use a workflow to populate that field. I can't use the custom lead field mapping for the same reason. Is there any way to do this with clicks? Or do I need code?

Alternatively, I can create some hidden fields that are populated on the opportunity, then create a flow button that populate the fields I need. (I wish flow triggers was still happening)

  • I was looking to use a Convert Lead tool but I can't figure out how to add custom field mappings and I've had no luck getting support from them. Dec 16, 2014 at 19:26
  • Does the Lead have a custom lookup field that you are trying to map to a custom lookup field on the converted Opportunity?
    – cropredy
    Dec 16, 2014 at 20:14
  • The lead does have a custom lookup to a custom object. This one works fine. The one I have trouble with is a custom lookup to a contact. Which doesn't exist until the lead is converted. Dec 16, 2014 at 20:45

1 Answer 1


You will need to use an after update trigger on Lead. The custom lookup from Opportunity to Contact has to be built after the Account - Contact - Opportunity - OpportunityContactRole are built

Curiously, I just answered this very question for another post here

trigger AddPrimaryContactToConvertedOpp on Lead (After Update) {
// [1] Build list of Oppos to update
List<Opportunity> oUpdList = new List<Opportunity> ();
for (Lead l : Trigger.new) 
    if (l.IsConverted && l.convertedOpportunityId != null)
        oUpdList.add(new Opportunity(id = l.convertedOpportunityId, contact__c = l.convertedContactId));

// [2] Update the converted Oppos
update oUpdList;  // could be Database.update(oUpdList,false) if you want partial successes
  • This is fantastic, thanks! If I wanted to add more fields would I do it at the end of line 6, right? Dec 17, 2014 at 20:26
  • 1
    Yes, your assertion is correct. Don't forget to write a testmethod to be able to deploy this (there are tons of examples around if you have never done this)
    – cropredy
    Dec 17, 2014 at 22:00

You must log in to answer this question.

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