You need to sign in to do that
Don't have an account?

Find out Account's/Contact's new Owner in a Trigger after Lead Conversion
Hi,
Is it possible to get to know the new Owner of the new created Objects Account/Contact in a trigger while a lead is being converted?
In the After/Before Insert Trigger of Account/Contact the OwnerID is set to the Owner of the Lead.
In After/Before Update Trigger of Lead, if I try to query Accounts/Contacts OwnerID (Using [SELECT OwnerID from Account where ID=:ConvertedAccountID]), I still get the ID of the user that owns the Lead, not the new User.
The After/Before Update Trigger of Account/Contact is NOT executed.
Any Ideas/Help?
Have you tried this?
trigger.old[0].OwnerId?
(ie Id oldOwnerId = trigger.old[0].OwnerId;)
thank you JeffStevens,
In lead conversion the Lead itself doesn't change the Owner - only the new created Account/Contact are assigned to the new owner. I'm looking for the new owner, not the old one.
Hi there,
Lead conversion is a special process, and according to the Salesforce docs.
I think this happens even whe you explicitly specify a new owner during the convert process.
More juicy details here: http://eu1.salesforce.com/help/doc/en/leads_convert.htm
Regards,
Anup
successforce,
I tried it, and in my case the Owner of Account/Contact in the After/Before Insert trigger was the current User (owner of the Lead - the system administrator). NO After/Before Update trigger is called :(
So salesforce changes the owner without calling Triggers (even though the Setting "Enforce Validation and Triggers from Lead Convert" is enabled)
How can I find out the new Owner? I can't imagine it's not possible ....
why do you think Update trigger should be called? Isn't this an insert process?
- Anup
OwnerID is being updated AFTER the Insert operation.The Account is inserted with another OwnerID. In the Salesforce database the Account is stored with the new OwnerID
For a developer to be able to react to this change, an update trigger should be called ...
According to this only Apex before triggers are fired.
http://eu1.salesforce.com/help/doc/en/customize_leadsettings.htm#ApexLeadConvertPref
Regards,
Anup
successforce,
thank you. Unfortunately my apex before Update trigger doesn't fire at all. Perhaps it fires if there are any workflows assigned.
The question remains: how can I access the new (destination) ownerid of Account/Contact in a trigger ?
okay - what about puttting the trigger on the Account, in an after update?
Then you can check for any matching Leads, (ConvertedAccountId) and the IsConverted field.
The Order of Execution is:
* OnBeforeInsert of Account (Lead was not changed yet)
* OnAfterInsert of Account (Lead was not changed yet)
* OnBeforeInsert/OnAfterInsert of Contact and Opportunity (Lead was not changed yet)
* OnBeforeUpdate of Lead (Select OwnerID from account where id=:Lead.ConvertedAccountID returns the OLD OwnerID)
unfortunately not.
This does not work for new Accounts/Contacts. It does work for existing Accounts/Contacts, though (in case the lead is converted to an existing Account/Contact).