0

I am trying to use the below relationship query in order to get my final Approval history data.

Select 
    id,
    p.ProcessInstance.Status,
    p.Actorid.p.lastactor.name,
    p.ProcessInstance.TargetObjectId,
    p.processInstance.CreatedDate,
    CompletedDate,
    p.LastActorId,
    p.processInstance.targetobject.type 
FROM ProcessInstanceNode p 
WHERE p.processInstance.TargetObject.type = 'order' 
    AND p.processInstance.Status = 'Pending' 
    AND p.NodeStatus='Approved' order by CompletedDate desc

But now I have to filter my records based on Current logged in user, i.e. AND p.ActorId =:UserInfo.getUserId();

So need to Fetch ActorId from ProcessInstanceStep object.

  • Add a subquery to get the steps, then iterate over them or sort and then limit 1, etc.... – Eric Sep 1 '15 at 13:06
1

You can use below query to fetch Approval History data.

SELECT CompletedDate, CreatedById, CreatedDate,Id,IsDeleted,LastActorId,
LastModifiedById,LastModifiedDate,ProcessDefinitionId,Status,SubmittedById
,SystemModstamp,TargetObjectId, (SELECT ID, ProcessNodeId, StepStatus,
Comments,TargetObjectId,ActorId,CreatedById,IsDeleted,IsPending,
OriginalActorId,ProcessInstanceId,RemindersSent,CreatedDate 
FROM StepsAndWorkitems ) FROM ProcessInstance
where ProcessInstance.TargetObjectId = <object id>

The above query will return Approval Process history of all the process instances created on target object id given in filter. You can further add filters in where clause as per your requirement.

  • How can we get Actor Name, Last Modified Name instead of ID's ? – Nilesh Borse Nov 27 '17 at 10:01

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.