1

I'm trying to pass parameters via URL to a multi-picklist field, but I'm finding that it seems to be impossible to build a pageRefence with non-unique parameters.

pageRef.getParameters().put(00Ne0000001cwJ4, 'value1');
pageRef.getParameters().put(00Ne0000001cwJ4, 'value2');

becomes this in the URL: &00Ne0000001cwJ4=value2

Even doing something like:

new pageRefence(url);

where you've built the full URL that includes the parameters yourself will still end up stripping the additional values. Are there any workarounds to this?

Thanks

  • 2
    Did you try a semicolon delimited list (e.g. param=value1;value2)? – Adrian Larson Dec 7 '16 at 23:03
  • I actually did, but passing it with a semicolon as a delimiter unfortunately does not work. From what I've seen, I believe that it tries to treat the whole string as 1 value (which doesn't work since it won't be a proper value). – Julien Dec 9 '16 at 0:08
1

As Adrian suggests, on the requesting side:

String[] values = ...;
Map<String, String> params = pageRef.getParameters();
params.put('00Ne0000001cwJ4', String.join(values, ';'));

and on the receiving side:

Map<String, String> params = ApexPages.currentPage().getParameters();
String[] values = params.get('00Ne0000001cwJ4').split(';');

The parameter values are automatically URL encoded and the appropriate ? or & parameter delimiter added as needed.

For the general, case choose a character (or characters) in the join/split that you know will not be present in any of the parameter values.

  • I'm just trying to pass values to a standard Salesforce page to populate some fields. With your solution I'd have to have an entirely custom page with a controller on the receiving side, which means anytime we want to add new fields to the layout, there would to be a code edit. Not very user friendly for regular admins & not a sustainable solution in the long-run. – Julien Dec 9 '16 at 0:12
  • @Julien Ok I see. Do standard Salesforce pages support a syntax for this e.g. doe the semi-colon separation work? I've never seen a "URL hack" for this though there is this unaccepted answer post Passing Multi-Select Picklist values to child record with URL hack. – Keith C Dec 9 '16 at 9:14
  • unfortunately semi-colon separation does not work. The link you posted is indeed the only way I've found to go about it (ie: having your URL being &00Ne0000001cwJ4=value1&00Ne0000001cwJ4=value2), but if trying to do it via PageRefence, it removes all the duplicate parameters :/ – Julien Dec 10 '16 at 17:54

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.