Passing Selected ID to Apex Class using Standard Set Controller

  • 1
  • Question
  • Updated 3 years ago
  • Answered

I am getting selected records ids but my main concern is In the apex class getselected method is used from Standard set Controller.

So my issue is that what should i pass in URL so that it accepts those selected records ID's because every time i am passing selected record ID's it gives me error message of Invalid ID.

I am trying to make One List View button from one of Apps.

So can you please assist me what we can do for the same?

Photo of Arpit


  • 1,514 Points 1k badge 2x thumb

Posted 5 years ago

  • 1
Photo of Zach McElrath

Zach McElrath, Employee

  • 53,824 Points 50k badge 2x thumb
Apex Standard Set Controllers look for one or more URL Parameters named ids , and then take the contents of each of these parameters and use this to define their set of selected records. 

So here's an example, say you have a Skuid page that shows a Table of Accounts. You have a Visualforce Page called "MapAccounts" that plots the locations of those Accounts on a Map. So you want to have a Mass Action on your Table that passes the Ids of selected Accounts to your Visualforce Page.

Here's what the JavaScript code for the Mass Action Snippet should be:

// Get the Ids of the selected items as an Array
var selectedItems = arguments[0].list.getSelectedItems();
var idsArray = skuid.$.map(selectedItems,function(item){ 
   return item.row.Id; 
// Pass these Ids over to our Visualforce Page = 
    + "?ids=" + idsArray.join("&ids=")
    + "&retUrl=" + encodeURIComponent(document.location.href);

Let's say on your Skuid Page you select 3 Accounts. This should generate a URL looking something like the following:

Notice how there are 3 separate URL Parameters all called ids --- this is what Apex Standard Set Controllers are expecting to find to determine their list of selected records, that is, what records are returned by StandardSetController.getSelected()
Photo of Prabir


  • 60 Points
Cool. Worked for me :)
Photo of Shmuel Kamensky

Shmuel Kamensky, Champion

  • 4,700 Points 4k badge 2x thumb
Wow. First snippet I've used and boy does it open up the possibilities.
Photo of Saikat Neogy

Saikat Neogy

  • 60 Points
arguments undefined error gives. Can you tell me the reason?
Photo of Rob Hatch

Rob Hatch, Official Rep

  • 44,868 Points 20k badge 2x thumb
Can't really give you a single reason.  This is a very standard JS error because you are asking for arguments somewhere and not getting any.  Maybe you have code written to be invoked in a snippet that is being called in an INline resource - and therefore no arguments are passed.

All I can reccomend is that you follow the console error into your code and determine where the error originates.  Hopefully its in custom code so you can dig into it and determine why there are no arguments being passed. 
Photo of Irvin Waldman

Irvin Waldman, Champion

  • 9,026 Points 5k badge 2x thumb
Sprinkle a few console.logs() if you have access to the code.  You can always step through the code using Chrome Developer Tools.  Search the community for hints on debugging JS and using developer tools.