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
Haroon AhmadHaroon Ahmad 

Capture URL for Approval Page for Opportunity at the approval submission

Hi,

My goal is simple.

 

For an Opportunity, when an approval request is submitted, caculate the URL for the Approval page, and store it in a custom Field in the Opportunity object. One of the steps in the approval submission is upating a field in the Oppty object. So, the approval submission is firing a Opportunity trigger.

 

What I'm trying to do is to capture the URL of Approval page of thye Oppty, in the After or Before update of the trigger. To do this I use the followihng query:

 

List<ProcessInstanceWorkitem> piWorkItems = [SELECT Id, processinstance.targetobjectid  FROM ProcessInstanceWorkitem where processinstance.targetobjectid in :opptyIdList];
    	

 But this query does not give me any results in either the before or the after update triggers for the Oppty.

 

But if I run this query after the record has been saved, then I do get a valid ProcessInstanceWorkitem record for this opportunity.

 

Looks like during the whole approval process (including the workflow and trigger fired), the ProcessInstanceWorkitem is not available to be read at all. (maybe because it is a system Object?)

 

Would appreciate confirmation/similar experiences.

 

Thanks!

 

-Haroon