Passing Selected ID to Apex Class using Standard Set Controller

Hi,

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?


Thanks.

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 window.top.location = "/apex/c__MapAccounts" + "?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:

https://skuid.na11.visual.force.com/apex/UseAccounts?ids=001G000001bOAAnIAO&ids=001G000000w0pikIAA&ids=001G000000sHLyXIAW&retUrl=https%3A%2F%2Fskuid.na11.visual.force.com%2Fapex%2FAccountList

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()

arguments undefined error gives. Can you tell me the reason?

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. 


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.

Cool. Worked for me :slight_smile:

Wow. First snippet I’ve used and boy does it open up the possibilities.

I have similar requirement to invoke an existing VF page (displaying list of records using StandardSetController) from my lightning component. In my JS i have constructed the URL as described above but the VF is only displaying the record corresponding to 1st Id passed in the URL.

JS code snippet:

var el = this.template.querySelector(‘lightning-datatable’);
var selected = el.getSelectedRows();
var arrayOfIds = ;
for(let request of selected){
     arrayOfIdsIds.push(request.Id);
}

this[NavigationMixin.GenerateUrl](
{
type: ‘standard__webPage’,
attributes:
{
url: ‘/apex/VisualForcePage?ids=’+ arrayOfIds.join(‘&ids=’)
}
}).then(generatedUrl =>
{
window.open(generatedUrl);

});

URL generated when it navigates to VF page is 

https://sample–devas.lightning.force.com/lightning/webpage/%2Fapex%2FVisualForcePage%3Fids%3Da1D3L0000000OE4UAM%26ids%3Da1D3L0000000DsRUAU

Is there something wrong with this url?