0

We have Custom Tab 'Approval Request' in our lightning application.The Purpose of this Tab is to display list of all the Pending Approval Process of all the objects.

If I want to query on ProcessInstanceWorkitem then I can query like this:

SELECT Id,ProcessInstanceId, ProcessInstance.TargetObjectId, 
                                  ProcessInstance.TargetObject.Name,
                                  ProcessInstance.TargetObject.Type, 
                                  ProcessInstance.CreatedBy.Name,
                                  ProcessInstance.CreatedDate,
                                  from ProcessInstanceWorkitem 

Similar Query we use it in our apex code.

I want to fetch the Parent Name of the Target Object so that whenever I Open the Approval Request then I can see the Parent Name of my Target Object Record.

e.g. I have a approval Request on Child object 'Potential Risk' of Parent Opportunity.So when I see the Potential Risk Record in Approval then it should display Parent Record Name which is Opportunity Name too.

I want to know if it is possible or not.As per the below link I am not able to get Parent Name of my Target object.

https://developer.salesforce.com/docs/atlas.en-us.api.meta/api/sforce_api_objects_processinstanceworkitem.htm

Can someone please suggest?

1 Answer 1

2

This requires two queries because TargetObject field is polymorphic on ProcessInstance.

SFDC provides OOTB support for the TargetObject.Name, TargetObject.Type (an SObjectType) and (I can't remember) - system audit fields.

You will need to do a separate query on Potential_Risk__c using ProcessInstance.TargetObjectId to fetch any fields on the parent object

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.