0

I am writing some Apex to query Approval processes.

The following SOQL query runs just fine in Developer Console Query Editor:

Select p.Id, p.ProcessInstanceId, 
p.ElapsedTimeInDays, 
p.ActorId, p.OriginalActorId, p.CreatedById, p.CreatedDate 
from ProcessInstanceWorkitem p

but when I attempt to use the same SOQL query in an Apex method like so:

List<ProcessInstanceWorkItem> piwi  = [Select p.Id, 
                p.ProcessInstanceId, 
                p.ElapsedTimeInDays,
                p.ActorId, 
                p.OriginalActorId, 
                p.CreatedById, 
                p.CreatedDate 
                from 
                    ProcessInstanceWorkitem p];

Then I receive an error:

No such column 'ElapsedTimeInDays' on entity 'ProcessInstanceWorkitem'. If you are attempting to use a custom field, be sure to append the '__c' after the custom field name. Please reference your WSDL or the describe call for the appropriate names.

Can anyone explain why the field is not valid in Apex or how I can change the query to access this field?

1 Answer 1

1

The issue is because those ProcessInstanceWorkitem fields are not available in the API version that your class is using. Running the SOQL directly in the Dev Console will use the API version.

If you check the metadata on your class you will see something like what is shown below. If you keep increasing the API number you will find that the SOQL will start to work when you increase it to the version that the fields were added in.

<?xml version="1.0" encoding="UTF-8"?>
<ApexClass xmlns="http://soap.sforce.com/2006/04/metadata">
    <apiVersion>20.0</apiVersion>
    <status>Active</status>
</ApexClass>

The ProcessInstanceWorkitem documentation mentions Summer '14 so that could be the API version they were introduced in.

You must log in to answer this question.

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