You need to sign in to do that
Don't have an account?
Lead Insert returning different Id?
I have an APEX class that is inserting Lead information, *randomly* (yes, I know there is no random) I'm getting back an Id from an existing Lead. There is only one "before insert" trigger and the only thing that does is query some other objects to populate a custom field with some instructions on what to do next with that lead.
Environment - this is running in Sites.
Pseudo-code and flow:
1. Instantiate variables via Controller:
public Lead ldNew {get;set;}
ldNew = new Lead();
2. Display and collect on VF Page
<apex:inputField value="{!ldNew.Email}" />
3. Insert Lead object
insert ldNew;
4. Requery Lead for instruction info
Lead ldRequery = [SELECT ... FROM Lead WHERE Id = ldNew.Id];
5. Send Emails to people, etc...
etc...
Right there between Step 3 and 4, sometimes I"m getting back an Id from an EXISTING LEAD instead of the expected new lead.
I'm stumped - ideas? Anyone seen this behavior before? I didn't think it was possible to return the Id from another Lead within a before insert trigger??!
-Andy
Not sure what is happening, but I'd expand the IdNew get; set; out and add some logging in to detect when a new value is being set.
Other than that I'd be on the lookout for extra static keywords somewhere in the code.
Cheers,
Daniel
This pseudo-code works fine, displays the same IDs:
So I'm guessing that it's something that you omitted.
99% of the time it returns the right Id - the code is sound.
It's weird, just every now and then it returns a different Id.
Nevermind - I'm recoding it differently.
-Andy
Sometimes, the best answer is to redo it and hope that you don't make the same, hidden mistake again. :)
Hello techman,
Did you solve the issue? What causing this issue?
Thanks,
Devendra
There has been no solution yet. Only happens on this one org (I put the code in another org and no problems recur).
Was a long shot if anyone had experienced it, we'll see what time tells.
-Andy
do you have any triggers on Leads that may affect it?
That's the kicker - we do, but as part of identifying what the heck was going on, I disabled all triggers and workflows.
-Andy