10

If you have a page using a standard list controller, like this:

<apex:page standardController="Account" recordSetVar="Accounts">

You can create a custom button for account lists allowing the end user to select records with checkboxes, and then click the button to navigate to that custom page with the selected records available using the {!selected} syntax. That's all well and good, but is there a way to navigate to such a page from another custom page that uses a custom controller?

i.e. MyPage is using MyController which wants to navigate to the page above, passing through a few account IDs to work with.

Research

I've looked at the form data passed through form standard pages to the page and there seem to be multiple parameters called ids which each have a different record ID stored in them. If I enter the page URL in the browser directly, and add multiple parameters called ids (e.g. '/apex/AccountsPage?ids=someacctid&ids=anotheracctid') I can loop over selected and see both accounts. Trying to create a page reference using something like this:

String url = '/apex/AccountsPage?';

for(Id acctId : listOfIds)
{
    url += 'ids=' + acctId + '&'; 
}

url = url.left(url.length() - 1)

ApexPages.PageReference pr = new ApexPages.PageReference(url);

Does not work, the system seems to remove the duplicate parameters and just leaves one (I think it's illegal to have multiple with the same name).

So is there a way to do this without creating a custom controller for the second page?

  • Don't think apex will allow you to do that. But it should work in javascript 'oncomplete' or 'onclick', did you try ? – Cloud Ninja Apr 22 '14 at 9:44
  • 1
    There is no informative statement on how duplicate parameters are handled, it seems it's up to the platform in each case, this is a good read, stackoverflow.com/questions/1746507/…, it seems PageReference falls into the non-deterministic category, since getParameters() gives a Map, which is what i expect internally it is doing within the constructor. – Andrew Fawcett Apr 22 '14 at 9:48
  • 1
    I was pondering over the StandardSetController.setSelected method, basically rolling your own URL parameters convention (which is probably safer anyway that depending on a reverse engineered API) and calling the setSelected method in the constructor. I'm not in a position to try this out at present though, may try later today. – Andrew Fawcett Apr 22 '14 at 9:50
  • I was thinking along the same lines @AndrewFawcett, but feel like it's a bit of a platform omission. – Matt Lacey Apr 22 '14 at 23:35
  • 1
    Yeah agree, "URL API to StandardSetController" – Andrew Fawcett Apr 23 '14 at 12:02
2

It's a HTTP POST request which is bit hard to replicate with PageReference (designed with GET in mind).

enter image description here

Your options are:

  1. share same controller extension across the pages, the variables will pass naturally. Similar to how the wizard example works.
  2. have a regular <form action="/apex/MyPage" method="post"> instead of <apex:form>
  3. Craft the URL yourself in JavaScript as you've already experimented - /apex/AccountsPage?ids=someacctid&ids=anotheracctid. There might be some JavaScript plugins to simplify that for you, not the least of them being the jQuery's functions around ajax calls.

First one sounds most clean to me but you want it controller-free. So I'd probably go with #2 then.

1

give the <apex:page> tag same for two pages

i.e

<apex:page standardController="Account" recordSetVar="Accounts"   extensions="MyController">

then you can share all controller variables for both the pages.

0

Adding parameters explicitely like this

http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_System_PageReference_getParameters.htm

has been helpful for me in similar situations.

I hope this fixes your issue, Rup

  • The problem with that is you can't put in multiple parameters with the same name :) – Matt Lacey Apr 23 '14 at 7:13
  • Try just adding the one parameter "ids=listofvzlues" this way – altius_rup Apr 24 '14 at 23:45
  • How do you delimit the list in a way that works with the standard list controller? – Matt Lacey Apr 26 '14 at 6:18
  • good question, Matt ! What would be the parameter name for the standardvlist controller ? – altius_rup Apr 30 '14 at 4:49
  • 1
    There's a parameter called wrapMassAction with a value of 1 that appears when you use a List button with selection options that links to a visualforce page. I suspect that this somehow alters the processor, but I don't know enough to make it a full answer. – sfdcfox Jun 22 '14 at 9:10

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.