0

I have a visualforce button that submits an approval request. I would like the method to return a PageReference that brings the user to the full Approval History related list. I can't seem to figure out how to do that without hardcoding the url.

Here is my code:

return new ApexPages.StandardController(theOpportunity).view();

It returns a url like this:

https://mydomain--staging.lightning.force.com/lightning/r/Opportunity/0063z000014zQWVAA2/view

I want it to return this:

https://mydomain--staging.lightning.force.com/lightning/r/Opportunity/0063z000014zQWVAA2/related/ProcessSteps/view
5
  • You'll likely need to get creative for two reasons: there's no guarantee the object of the record you're clicking on has any approval processes and there also is no guarantee that it has any associated approval history. Check out Lightning Experience Page References where there is a navigation event to navigate to a record's related list.
    – nbrown
    Oct 20, 2021 at 20:38
  • I do already check whether there is an open approval process, as follows. Because my VisualForce page is used to submit an approval process, and it will refuse if there is already one pending.
    – Bo Laurent
    Oct 21, 2021 at 22:58
  • SELECT Id, ProcessDefinition.Name FROM ProcessInstance WHERE TargetObject.id = :theOpportunity.Id AND CompletedDate = null
    – Bo Laurent
    Oct 21, 2021 at 23:00
  • I hesitated to hard code URL, but given the resource that @nbrown referenced, I am using the following code, which does what I want.
    – Bo Laurent
    Oct 21, 2021 at 23:17
  • return new Pagereference('/lightning/r/Opportunity/%/related/ProcessSteps/view'.replace('%', theOpportunity.Id));
    – Bo Laurent
    Oct 21, 2021 at 23:17

1 Answer 1

0
return new Pagereference('/lightning/r/Opportunity/%/related/ProcessSteps/view'
    .replace('%', theOpportunity.Id));

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .