I am querying in the Workbench with SOQL. I need to query a history object to a custom field, but I want to see changes only to a certain field. What is the syntax to say WHERE Field = MyTargetField ?

I tried this:

SELECT Field, NewValue, OldValue 
FROM MyCustomObject__History
WHERE Field = myTargetField__c

but this generates an error:

WHERE Field = myTargetField__c

ERROR at Row:3:Column:14
Bind variables only allowed in Apex code

  • Just a note, whenever you get an error message you should include its text verbatim.
    – Adrian Larson
    Apr 18 '17 at 0:42

You need to wrap the value in single quotes ('...'):

SELECT Field, OldValue, NewValue
FROM MyObject__History
WHERE Field = 'Custom_Field__c'
  • I tried that, and that returns empty, it does not match with my target field.
    – ALisboa
    Apr 18 '17 at 0:50
  • @ASignor Are you sure you actually have history records where that field has changed?
    – Adrian Larson
    Apr 18 '17 at 0:51
  • Actually I'm not. You are probably right. Thank you.
    – ALisboa
    Apr 18 '17 at 0:52
  • Easy enough to verify. Just change the value in that field on an existing record. :)
    – Adrian Larson
    Apr 18 '17 at 0:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.