I'm writing a short snippet of code to get which records of a certain type were approved, and by who. However, I don't have an id list- I have an sObject type. I know I can filter the id values after the query with something like:
if (String.valueOf(processInstance.TargetObjectId).startsWith('006')) { ... }
But, I'd rather filter these values out in a query instead of having to do it in apex. I tried using the LIKE
keyword to filter the query, as below:
SELECT Status, TargetObjectId FROM ProcessInstance WHERE TargetObjectId LIKE '006%'
But this query fails with:
INVALID_QUERY_FILTER_OPERATOR
[object Object]: TargetObjectId FROM ProcessInstance WHERE TargetObjectId LIKE '006%' LIMIT ^ ERROR at Row:1:Column:58 invalid operator on id field
I know the docs say the LIKE
operator can only be used with String
types, but I was under the impression that the Id
type was just a wrapper over the String
type. Is there any way I can get this filter working inside a soql query?
TargetObjectId
and theStatus
from theProcessInstance
, so I'd rather construct the objects from the single query. – battery.cord Jul 22 '16 at 17:31