As you may know when you try to convert a lead ,during the execution of the lead convert ,the Account/Contact/Opportunity objects owner id's are set as the current user Id instead of the lead original owner id which can be problematic if you are programming your logic based on the correct owner id.

The Account/Contact/Opportunity owners are set to the original lead owner after conversion is finished (however I put debug statements in after lead update which is the last trigger running in conversion process, and Owner Id is still user Id. Where or when salesforce sets the correct owner id for those objects is a mystery to me)

Take a look at this post, and scroll down and see what sfdcfox says. Lead Conversion Trigger Order of Execution

The solution steps I came up with:
1 - I created a custom formula field named Lead_OwnerId_Custom__c on lead. The value of this field is Lead.OwnerId. Also I created a text field named Source_Lead_OwnerId__c on Account.

2 - Then I go to object management settings for leads, fields section, then I click on Map Lead Fields.

3- I map the Lead_OwnerId_Custom__c from Lead to Source_Lead_OwnerId__c on Account and hit save.

4- Now I try to convert a lead. I have written debug statements in before insert trigger for Account to show the Account.OwnerId and Account.Source_Lead_OwnerId__c.

Result: Account.OwnerId is set to current user id, which is wrong. But Account.Source_Lead_OwnerId__c has stayed as Lead original Owner Id which is correct and that's what I want.

So my question is, do you think this is a good work around for the original problem described above since I am relying on some undocumented feature of the language?

  • 1
    What's your goal? To know who the owner was? To change the owner? What's the underlying problem you're trying to solve?
    – sfdcfox
    Nov 21, 2015 at 2:15
  • The goal is to have the correct owner id during the lead conversion in "account before insert trigger" since we have to run a query on the owner id
    – Masoud Az
    Nov 21, 2015 at 3:52
  • Hi Masoud, When I tried to reproduce this I got some different behaviour. Though I converted lead owned & created by A user in context/by B user. Final Account/Contact/Opportunity got created with A as owner and B user as createdby and lastmodified by users. YOu can check this i.imgur.com/gDmTgDl.png?1 Here contact owner is Kiran Machhewar who created lead first and KMForceOne is the user who converted the lead. Will you please check if there is something in trigger of A/O/C which ares setting current user as owner. Let us know your views on it so that we could help. Nov 21, 2015 at 6:03
  • @KiranMachhewar The problem isn't post transaction, but simply during the conversion (e.g. in before/after triggers). Personally, I think that's a bug, but it is what it is.
    – sfdcfox
    Nov 22, 2015 at 7:18
  • @sfdcfox thanks for clarifying. If that is the case then Masoud Az could go ahead and use source_lead_ownerid since at the end once lead conversion is done he can use owner Id of account directly. I don't see any harm in that. Nov 22, 2015 at 7:52


Your Answer

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

Browse other questions tagged or ask your own question.