6

I am going through code that does approvals and I see the following query:

Select Id, TargetObjectId, Status,
    (
        Select Id, ProcessInstanceId, ActorId, Actor.Name, StepStatus, Comments 
        From StepsAndWorkItems
        Where 
            StepStatus = 'Pending'  and
            isDeleted = false 
        Order By 
            Createddate Desc
        Limit 1
    )
From ProcessInstance
Where
    isDeleted = false and
    TargetObjectId = 'a0WM0000002F8gdMAC' and
    Status = 'Pending'
Order By 
    Createddate Desc
Limit 1

This works fine. From what I can see, the ProcessInstance object is somehow connected to the StepsAndWorkItems object that's referenced in the subquery. So this assumes that StepsAndWorkItems is an actual object that can be queries. And yet, if I try this:

Select Id, ProcessInstanceId, ActorId, Actor.Name, StepStatus, Comments 
From StepsAndWorkItems
Where 
    StepStatus = 'Pending'  and
    isDeleted = false 
Order By 
    Createddate Desc
Limit 1

I get an error stating: sObject type 'StepsAndWorkItems' is not supported.

Can someone shed some light as to why this is happening?

1 Answer 1

8

The query which you are attempting to execute is using a child relationship name, StepsAndWorkItems , which isn't valid in that context.

StepsAndWorkItems is the child relationship name for ProcessInstanceHistory under the ProcessInstance object.

The underlying objects are ProcessInstanceStep and ProcessInstanceWorkItem. You can query those two objects individually but you cannot use the child relationship name to query them both at the same time without doing it from within the parent context.

3
  • Wow, that's rather inconsistent naming. Most other relationships default to being named after the object and not something completely different.
    – Mike Chale
    Commented Aug 16, 2013 at 18:31
  • Yeah, I just figured it out too. I didn't realize you query via the relationship rather than a join. Commented Aug 16, 2013 at 18:35
  • More examples: ActivityHistories and OpenActivities, which query Task and Event objects that meet certain criteria (Task IsClosed = true or Event ActivityDate < TODAY; Task IsClosed = false or Event ActivityDate >= TODAY). These relationships don't reflect actual tables, but exist as a convenience to developers. You might think of them as views rather than tables, except that they can't be queried directly; as you've noted, they have to be used in a sub-query context.
    – sfdcfox
    Commented Aug 17, 2013 at 4:12

You must log in to answer this question.

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