1

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?

  • 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 Oct 6 '16 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 – Lalitha sfdc Oct 6 '16 at 7:28
4

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..
    }

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

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.