When triggers are executed during lead conversion, the user converting the lead is recognized as the record owner.
|Knowledge Article Number||000171116|
|Description||When a lead is converted, the user converting the lead is recognized as the "Lead Owner" when triggers and workflow rules are executed.
Example scenario :
- Lead is auto converted for user with apex code and calling Database.convertLead() method or through the standard procedure.
- Salesforce creates the new Account (owner at this point in time is the current user) -
- If the trigger is fired on the new DML operation(insert) and we are populating some other field based on the lead owner then the results will not be correct.
- This is because of the fact that inside the trigger the lead owner will change to the currently logged in user.
Documentation says :- " If you have a trigger set to fire when new records are created, the trigger temporarily assigns a system user as the owner of the created records. After the trigger finishes, the owner is set to the lead owner. "
Anything that you want to do in which you are involving the lead owner should be done in future class. On insert the trigger will be called and that trigger will call the future class(in real time) which will be processed/executed after the trigger ends(since the future methods are async). Since the trigger ended before the future class starts executing, so the lead owner will not be the currently logged in user(current user) but the actual lead owner.