Skip to main content
Hieu Truong (Hylaine) ha preguntado en #Apex
Hello,

I'm trying to filter NewValue and OldValue on OpportunityFieldHistory and am getting an error on the Query Editor.

Here's my statement: Select Id, CreatedById, CreatedDate, Field, NewValue, OldValue from OpportunityFieldHistory Where Field = 'StageName' AND CreatedDate = Last_Month AND OldValue !='Owned Lead' AND NewValue='Owned Lead'

Error Message: [object Object]: AND CreatedDate = Last_Month AND OldValue !='Owned Lead' AND NewValue='Owned ^ ERROR at Row:1:Column:152 field 'OldValue' can not be filtered in a query call

Any ideas anyone?

Thanks,

Hieu
1 respuesta
  1. 22 feb 2018, 21:26
    You cannot able to use  OldValue and NewValue in where clause OpportunityFieldHistory object. Please refer this link 

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

    Use below Query to get the data and Filter it by using Apex code 

    Select Id, CreatedById, CreatedDate, Field, NewValue, OldValue from OpportunityFieldHistory Where Field = 'StageName' AND CreatedDate = Last_Month 
0/9000