Prepopulating fields using URL hacking – Part 5: Multi-Select picklists

URL Hacking Series
Prepopulating fields using URL hacking – Part 1: The Basics
Prepopulating fields using URL hacking – Part 2: Prepopulating custom fields
Prepopulating fields using URL hacking – Part 3: Handling Special Characters
Prepopulating fields using URL hacking – Part 4: Passing in the Record Type
Prepopulating fields using URL hacking – Part 5: Multi-Select picklists
If you have been following my series on URL hacking, you must be an expert reading salesforce URLs by now. However, I recently found that you can never learn enough – one of my project requirements was to pre-populate the value for a multi-select picklist.
Here’s the situation, I added a custom multi-select picklist to the Contact object – here’s how it looks:-
image 
With this setup, suppose I want the Contact Edit page to load with the first two values in the “MyMultiSelectPicklist” field selected. Here’s the URL to do it:-
https://na9.salesforce.com/003E000000HCekT/e?retURL=%2F003E000000HCekT&00NE0000004AOP9=Value%201&00NE0000004AOP9=Value%202&00NE0000004AOP9=Value%205
Let’s go one by one – look at the highlighted part in the above URL. Here, “00NE0000004AOP9” is the ID of the multi-select picklist. How did I know ? To understand, first right-click on the multi-select picklist, and select “Inspect Element”. I’m assuming you are using Firefox or Chrome as your browser. Here’s how it looks in my chrome browser:-
image
If you look at the highlighted sections, it is clear that the ID for the multi-select picklist’s left side list box is “00NE0000004AOP9_unselected”, and that of it’s right-side list box is “00NE0000004AOP9_selected”. Multi-select picklists are a little special – you can get the ID of the multi-select picklist by removing the “_selected” or “_unselected”. So, that is how we get the ID “00NE0000004AOP9” as the ID for our picklist.
Next, look at the value being passed - “Value%205”. If you have read this article in this series, you would be able to spot that this is a URL encoded string. So, the “%20” in this case is the URL encoded value for a white space character. So in reality, the parameter value that we are passing is “Value 5”.
Let’s look at the URL again -
https://na9.salesforce.com/003E000000HCekT/e?retURL=%2F003E000000HCekT&00NE0000004AOP9=Value%201&00NE0000004AOP9=Value%202&00NE0000004AOP9=Value%205
As is clear from the highlighted values above, we are passing the same ID three times, with different values. And this is how you pass values for the multi-select picklists – you pass multiple values for the same picklist ID. So, in the above example, I am passing in values “Value 1”, “Value 2” & “Value 5”. Here’s what it looks like in my org when I visit that URL-
image
So there you go, you can now even pass in URL values for multi-select picklists.





2 comments:

  1. Is it possible to do this dynamically between two multi-select picklists? For example, I want a custom button that creates a new case from a custom button on opportunity and pass the value Opportunity.MultiSelect1 to Case.Multiselect2.

    I don't think its possible, short of perhaps a formula on opportunity that concatenates the values, but this is not scalable for this use case.

    ReplyDelete
  2. Yeah, passing via formula field seemed to be the way to go, until I actually tried it... I was able to construct a URL that simply has a colon-seperated list of all picklist values, but when I tried to substitute the colons with the destination picklist ID (because for passing values to multi-select picklists, it needs Id=value&Id=value&Id=value...), it did not work. Turns out you can't use multi-select picklists in the substitute function.

    Then I tried creating a formula field that simply was the value of the multi-select picklist, and it turns out you can't use multi-select picklists in formula fields.

    So, I'm afraid the only way to go is to create a custom javascript button, that iterates through all the values in the picklist and creates the URL by hand. Not the easiest solution, but definitely scalable for your case.

    ReplyDelete