You need to sign in to do that
Don't have an account?
Lead History Table difference between Production / Sandbox
Hi Support / PM,
I am working with the LeadHistory table at same place in my code,
to find the previous owner of a Lead.
The funny thing (and the reason of this post) is, that in my production the "oldValue" field contains/returns the ID of the previous owner and in my Sandbox it returns the Name.
I didn't changed the API-Version, so this should not be the problem.
This is my query:
LeadHistory leadHistory = [ SELECT Field, LeadId, OldValue, CreatedDate FROM LeadHistory WHERE LeadId = :leadId AND Field = 'Owner' ORDER BY CreatedDate DESC NULLS LAST LIMIT 1 ];
and this is my Debug output:
System.debug('oldValue content: ' + leadHistory.OldValue);
Again: For production it returns ID, for Sandbox it returns Name.
It's not a problem for my app, as I quickly fixed it, but I wonder how this can differ between two orgs.
You can run the code from anonymous by putting a lead ID in the code. Of course you need field tracking on Lead Owner and at least one Owner change.
Thanks,
Hannes
P.S. We still have no LeadHistory in Apex Tests...
Looking into the LeadHistory table is very strange. For each History entry it creates two entries in the table.
One contains the names and the other entry contains the IDs.
How should I make sure to get only the rows which have a User IDs in "NewValue"?
Add a WHERE to make sure "NewValue" starts with '0052'!? ... Sounds like a dirty workaround ;)
(EDIT: Would not even work, because: "field 'OldValue' can not be filtered in query call")
Thankful for any help.
Here's a screenshot of the query + result:
http://img838.imageshack.us/img838/6610/sandbox.png
I was looking for Apex code coverage for a trigger which has references to LeadHistory table(like querying etc) and saw your note "We still have no LeadHistory in Apex Tests...". So what you are saying is we cannot write test scripts if we have used LeadHistory object ? Am i getting it right ? Please let me know. Also is there any place/doc where salesforce confirmed this ?