function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
bvramkumarbvramkumar 

Wrong Account OwnerId while converting lead to Account.

Hi Pals,

 

I am getting a possibly weird issue while doing lead converstion to an acount.

 

I have trigger on Account, that should copy the ownerId into another lookup-to-user field if the ownerId is a user(Not a Queue). Now... this works fine if the users are directly creating the accounts but fails while doing lead conversion.

 

The test case is,

1. Create a Lead

2. Click on Convert.

3. Change the Account Owner field to any user other than current user and proceed with Conversion. This will fire a trigger on Account Insert.

4. Now, what I expected in my trigger is the correct ownerId set by the user, But for a reason I have been unable to find, it always set the ownerId to current user.

 

Now you may think tha my code is wrong. Thats what I thought and reviewed my code hundred times and a hundred debugs. What I found from debug logs is that, it does not take the Account owner set by the user but always takes the current User. I searched boards but did not find any similar problem/solution.

 

You might also think there many some other triggers or workflows running after my trigger which are resetting the field in which i am expecting the correct value, but there is one and only one Account trigger and no workflows etc.

 

I am lost and cant find a reason for this issue. Please help... and it will be greatly appreciated.

 

Thanks

Vishnu

bvramkumarbvramkumar

I shifted my code to a future method thinking that correct account ownerId will come in after sometime, that did not work either.

bvramkumarbvramkumar

I tried again and again to resolve this without success. Can somebody help me please.

 

Thanks

Vishnu

bvramkumarbvramkumar

This issue has also been discussed here http://boards.developerforce.com/t5/Apex-Code-Development/Owner-ID-trigger-on-Account-I-need-some-help/td-p/405225 in a different way. I think the only solution is schedule batch apex that will correct the owner copy value asynchronously since @future method very instantaneous.

Jerun JoseJerun Jose
Are you aware of this snippet from the docs?

Before triggers associated with the following operations are only fired during lead conversion if validation and triggers for lead conversion are enabled in the organization:

insert of accounts, contacts, and opportunities
update of accounts and contacts

I got this from
http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_triggers_ignoring_operations.htm
bvramkumarbvramkumar

Thanks Jerun. In my case trigger is getting fired but a wrong value is coming in ownerId field in Trigger.new. Thanks Again for the link. I will study through it and will see If my Org. is missing something.

bvramkumarbvramkumar

I checked my Org. and that setting is enabled. I am feeling really crazy about this issue.

bvramkumarbvramkumar

I fired a dummy update in insert case and tried to set the owner copy field. It still gives wrong value. Probably the issue is because the upate is called immediately after Insert call. I can say that the correct value will never come in trigger context unless it is another separate transaction. I am feeling like there should be another specific action like a button click on detail page that will sync up all the accounts with correct values.