function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
shakila Gshakila G 

How to fetch process instance step related records with custom object subquery

HI All,

Am trying to fetch Custom object related Approval process records information from processinstance step using soql workbecn.
Select Account__r.Name,Team_Member__r.Name ,Team_Member__r.ISActive,Team_Member_Email__c,Team_Role__c, Status__c,RHMS_Approval_Status__c, Approval_Status__c ,(SELECT ProcessInstance.TargetObjectId ,Comments FROM ProcessInstanceStep)from Account_Team__C
where ID='a4Qc0000000kBDt'

Am getting following error..

Didn't understand relationship 'ProcessInstanceStep' in FROM part of query call. If you are attempting to use a custom relationship, be sure to append the '__r' after the custom relationship name. Please reference your WSDL or the describe call for the appropriate names.

Kindly let me know ..How to fetch alll those records using workbench..

you cannot fetch approval records by applying direct soql on custom object. There is different set of objects like process instance, process defination, processinstancestep, processDefination and others  which strores approval related data like you can check following link.
You can explore these objects on workbench in SOQL query section

shakila Gshakila G

Thanks for the update.

I tried that option ..

Select Account__r.Name,Team_Member__r.Name ,Team_Member__r.ISActive,Team_Member_Email__c,Team_Role__c, Status__c,RHMS_Approval_Status__c, Approval_Status__c ,(SELECT Id, (SELECT Id, StepStatus, Comments FROM Steps)
FROM ProcessInstances)from Account_Team__C
where ID='a4Qc0000000kBDt'

IF trying to fetch that way... am getting follwoing error..

MALFORMED_QUERY: SOQL statements cannot query aggregate relationships more than 1 level away from the root entity object.

So only itried to fetch directly from process instanse step....

Kindly provide some solution to fetch all the information
Not getting what exac information you are trying to retrive but you can try following

this is rougly you can get information 
ProcessInstance p=[SELECT id,IsDeleted,LastActorId,LastModifiedById,LastModifiedDate,ProcessDefinitionId,Status,SubmittedById,SystemModstamp,TargetObjectid FROM ProcessInstance where TargetObjectid='a4Qc0000000kBDt']
Account_Team__C at=new Account_Team__C();
at=p.TargetObjectid;//Now at have custom object id. using that you can retrieve that record related information

shakila Gshakila G
Am not looking the feasibilities for Apex class...
Just need to write a soql query to generate all those information with 1 set of query...

Only soql query...My third party application required only kind of soql query not Apex class..
i guess following u r asking for
Select id,name from Account where id in (select TargetObjectid from  ProcessInstance where TargetObjectid='a4Qc0000000kBDt')
Modify the above query as per your custom object.. i tried it on my trial instance
shakila Gshakila G
NOt like this..I need fetch details from both the object not only one