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
Raja Bipin Chandra  M BRaja Bipin Chandra M B 

SOQL Relationship Quieries: how to fetch

Hello All,

I am joining objects to get the Approval comments, actor for the specific target object id. However, i need to know how to fetch the data from the result list of data.Please help!
processinstance = [SELECT Id,TargetObjectid, Status,(select id,actor.name from Workitems),(SELECT Id,StepStatus, Comments,Actor.Name,ActorId FROM Steps) FROM ProcessInstance where TargetObjectId=:setOfQuoteId];
	
	for(ProcessInstance pi:processinstance){
      ActorId.add(pi.ProcessInstanceStep.ActorId); // Error is here
		//ActorId.add(pi.ActorId);
	}

Thanks,
Raja
Best Answer chosen by Raja Bipin Chandra M B
ManojjenaManojjena
Hi Raja ,

Try with below code ,Iterate with processInsatanceSteps .
processinstance = [SELECT Id,TargetObjectid, Status,(select id,actor.name from Workitems),(SELECT Id,StepStatus, Comments,Actor.Name,ActorId FROM Steps) FROM ProcessInstance where TargetObjectId=:setOfQuoteId];
	for(ProcessInstanceStep pi:processinstance.Steps){
		ActorId.add(pi.ActorId); 
	}

Thanks 
Manoj

All Answers

ManojjenaManojjena
Hi Raja ,

Try with below code ,Iterate with processInsatanceSteps .
processinstance = [SELECT Id,TargetObjectid, Status,(select id,actor.name from Workitems),(SELECT Id,StepStatus, Comments,Actor.Name,ActorId FROM Steps) FROM ProcessInstance where TargetObjectId=:setOfQuoteId];
	for(ProcessInstanceStep pi:processinstance.Steps){
		ActorId.add(pi.ActorId); 
	}

Thanks 
Manoj
This was selected as the best answer
Mudasir WaniMudasir Wani
Hi Raja,

You need to find the relation name
GoTo Steps object and search for MasterDetail(Lookup) and locate the ProcessInstance object and see what is the relationship name 
Say the name is ProcessInstanceStep__c.
In your code you are required to use ProcessInstanceStep__r

And the code should look like 
 
processinstance = [SELECT Id,TargetObjectid, Status,(select id,actor.name from Workitems),(SELECT Id,StepStatus, Comments,Actor.Name,ActorId FROM Steps) FROM ProcessInstance where TargetObjectId=:setOfQuoteId];
	
	for(ProcessInstance pi:processinstance){
      //I assume that your relationship API name is ProcessInstanceStep__c
      ActorId.add(pi.ProcessInstanceStep__r.ActorId); // Error is here
		//ActorId.add(pi.ActorId);
	}


Donot forget to select best answer to make our efforts visible in the developer forum.
Please mark this as solution by selecting it as best answer if this solves your problem, So that if anyone has this issue this post can help
ManojjenaManojjena
Hi ,

Above objects are not custom object .All are internal object repalted to Approval process . TargerObject is nothing but the sobject in which the approval proceess is ,Which ia always the parent obejct related to processInstance and processInstancestep is the child of ProcessInstance object and the relaionship name is Steps .Also two more object related to one is Processinstancehistory and ProcessInstanceWorkItem .

Any doubt please let me know .