2

I'm trying to query the date from the history object where the last status (field) is 'Request Approved' I tried the following query but unable to query on NewValue field on the history object.

error: NewValue' can not be filtered in query call".

SELECT CreatedById,CreatedDate,Field,Id,IsDeleted,
       NewValue,OldValue,ParentId FROM custobj__History 
WHERE ParentId = 'a1228000000fagQ' 
  AND Field = 'Status__c' 
  AND NewValue='Request Approved'

Can Someone Help On this?

2
  • as described in error. You can't use NewValue in query filter. You can just filter with field name use createdDate desc. So you will get the latest one first
    – Ratan Paul
    Commented Oct 6, 2016 at 7:24
  • If I take the latest CreatedDate I will not Get the status as Request Approved as there are several other Status after Request Approved so it will not work Commented Oct 6, 2016 at 7:28

1 Answer 1

5

You cannot use the NewValue field in a query call, no way around it.

https://developer.salesforce.com/docs/atlas.en-us.api.meta/api/sforce_api_objects_entityhistory.htm

The field is not filterable.

You will have to do a full query and pull out the data in a loop i.e.

for( custobj__History hx : [SELECT CreatedById,CreatedDate,Field,Id,IsDeleted,
       NewValue,OldValue,ParentId FROM custobj__History 
WHERE ParentId = 'a1228000000fagQ' ]{

    if(hx.NewValue == 'Request Approved'){
        //Add to list, do something etc..
    }

}
3
  • Just a update: the field apparently is filterable now. Commented Jan 31, 2017 at 17:58
  • @RenatoOliveira - Not according to the v39 documentation. I have not actually tried it though
    – Eric
    Commented Jan 31, 2017 at 19:26
  • Well, I don't know about v39, but on v38 it works... Commented Jan 31, 2017 at 19:27

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .