You need to sign in to do that
Don't have an account?
jjulian
Redirecting to an objects list view from APEX controller.
From within my apex controller, how do set PageReference to redirect to an object's list view page?
The only documented way of doing this is through visualforce:
<apex:page action="{!URLFOR($Action.Account.List, $ObjectType.Account)}"/>
However, I want to be able to do this from the controller instead:
public PageReference confirm() { // Do prep data PageReference ref = new PageReference(); // ??? redirect to object's list view return ref; }
There is one more way its kind of kludgy. Hardcode the id of the list view (not recommended but it'll work for sure)
Go to the tab and click edit on view which you want to redirect to copy id. And then in the controller use the following code
PageReference ref = new PageReference(/{objectprefix}?fcf=00BO0000000LhtN);
for account : PageReference ref = new PageReference(/001?fcf={ViewID});
All Answers
There is one more way its kind of kludgy. Hardcode the id of the list view (not recommended but it'll work for sure)
Go to the tab and click edit on view which you want to redirect to copy id. And then in the controller use the following code
PageReference ref = new PageReference(/{objectprefix}?fcf=00BO0000000LhtN);
for account : PageReference ref = new PageReference(/001?fcf={ViewID});
Example redirect to Account List View:
If you need to get to the landing page append a /o after the result.getKeyPrefix():
I think hardcoding the URL with ID's its not betterway, and above mentioned one might fail, if the user switched to lightning experience. This will work in both classis and lightning.