Monday 7 March 2016

Redirecting to selected list view

Hello Awesome Salesforce Developers ,

In one of my project I got following requirement :
1. Add custom button in list view. 
2. User will select the list view and select the records from the list view and on the     custom button click (added in step (1) ) user will be redirected to another page       where he perform certain operation.
3. After operation is over then on click of another custom button on Visualforce          page say "Return to List View" user should redirect to list view he selected              in the step (2)


The challenging part in this task was to get selected list view as we need to redirect user to list view selected in previous step.

If you check the URL of any list view it is constructed as follows : 

https://ajaytrailhead-dev-ed.my.salesforce.com/001?fcf=00B28000003fFfg
----------- Domain Name -------------------------/Object Prefix ? fcf= Id of the list view 

"fcf" is the parameter used to identify the list view Id. 

So you just need to construct the redirection URL in the above format.

Next question is from where we will get value for "fcf" parameter ?
Use Apexpages.currentpage.getParameters().get('fcf'); and you are set !

We got all the parameter now we just need to form the redirect URL explained in the following class.



















The associated Visual force page :











The custom button code 










Add above custom button to Search Layout --> Account List View.

Cheers !!! 



2 comments:

  1. Hi Ajay,
    Thanks for the good blogs, just to mention there is a correction that needs to be done,
    the code snippet "Apexpages.Currentpage.getParameters().get('fcf'); needs to be changed to Apexpages.currentpage().getParameters().get('fcf');"

    Please update the blog, and thanks for the good content, as always

    ReplyDelete
  2. Thanks Saket for the feeback. Updated the blog!!!!

    ReplyDelete