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
wt35wt35 

SOQL issue: not retrieving old and new value

Hello

 

I have a custom object for which I want to retrieve some field history.

For this I use the following SOQL query:

SELECT Field,NewValue,OldValue FROM Car__History

 

But it only pulls out the Field names, not the Old and New values, any ideas?

 

Thanks

Best Answer chosen by Admin (Salesforce Developers) 
Jia HuJia Hu
First, can you see the new/old value from related list,

If you can see it, you can query it in Execute Anonymous in Eclipse or Developer Console.

But you can't see the new/old value in the SOQL query window in salesforce.schema of Eclipse.

All Answers

Jia HuJia Hu

1. in the Custom Fields & Relationships, click 'Set History Tracking',
make sure which one you are tracking

2. in the Record detail page, click Edit Layout, in the Related Lists, add History to the page,

3. Then you will see the Tracked Changes on the Record page, and also you can query it by Apex

wt35wt35

Hello Jia

 

I have done all you have mentioned (it was arleady done actually).

 

It doesn't work, when I do my SOQL query, I do get rows for each track change but not the "old value" and "new value".

 

Marc

Jia HuJia Hu
First, can you see the new/old value from related list,

If you can see it, you can query it in Execute Anonymous in Eclipse or Developer Console.

But you can't see the new/old value in the SOQL query window in salesforce.schema of Eclipse.
This was selected as the best answer
wt35wt35

Thanks Jia

 

I tried in Anonymous Block and also Data Loader, both worked.

 

I was originally using workbench: https://workbench.developerforce.com/


I think it is a just a limitation of this tool specifically.

MyGodItsColdMyGodItsCold

I too am having trouble getting APEX access to OldValue, NewValue. I'll keep you posted. One thing I do notice in my Data Loader extract is that when the Field is a Multi Select Pick List, I don't see the values.

 

Further the code that I'm writing seems to choke when I assign the contents of OldValue, NewValue to a variable - as I read it, OldValue, NewValue is "Any Type" - meaning they take on the type of the Field in question.

 

I can't imagine no one is using History within APEX to do useful processing!

Maggie Longshore 2Maggie Longshore 2
This link no longer works.