I am trying to select records from list view custom button. I want to pass the selected record ids in the paramaters.

I tried the below and its not working for me.


I am passing the selected record ids to the listofacccounts attribute in the lightning component. Am I missing anything here.

Here is my lightning component and the controller :


<aura:component implements="lightning:isUrlAddressable">
>     <aura:attribute name="listofAccounts" type="List" />
>     <aura:handler name="init" value="{!this}" action="{!c.onPageReferenceChange}"/>
>       {!v.listofAccounts[0]}. 

Controller :

    onPageReferenceChange: function(cmp, evt, helper) {
        var pageRef = cmp.get("v.pageReference");
        var listofAccounts = myPageRef.state.c__listofAccounts;
        cmp.set("v.listofAccounts", listofAccounts);

I get this error whenever I click the List view custom URL button

"Invalid request, post must use JSON"

  • 1
    Please edit your post to include what you've done in the lightning component as it's there you're utilizing isUrlAddressable – Kris Goncalves Dec 24 '19 at 16:34
  • @KrisGoncalves, I have added further information. – pragii Dec 24 '19 at 17:32
  • can you add code for where u r setting pagereference and navigationservice firing? – sdandamud1 Dec 24 '19 at 19:36
  • @sdandamud1 : I am referring to developer.salesforce.com/docs/component-library/bundle/…. So basically I want my custom button on the list view to capture the selected record ids and send it to the lightning component. I see the latest release on URL addresable implements can do it. But not sure if I am doing it right. I am calling the lightning component from my button ( as shown above). – pragii Dec 24 '19 at 23:46

As far as I know, we cannot use {!GETRECORDIDS($ObjectType.Account)} to redirect to a Lightning component via URL.

There is another alternative using a Visualforce page, whereby the VF processes the selected recordids from list view then redirects to the lightning component.

Hope this helps

See working example below for account object

Visualforce page

<apex:page standardController="Account" recordSetVar="accs" extensions="VFC_ProcessAccRecords" action="{!redirectToLC}" />

Extension apex class

public class VFC_ProcessAccRecords {
      public List<Account> selAccLst;
      public String accIds;

      // Constructor
      public VFC_ProcessAccRecords(ApexPages.StandardSetController cntlr){
           selAccLst = cntlr.getSelected(); //get selected records from account list view
           accIds = '';  
           for(Account acc : selAccLst){
               accIds += acc.Id + ','; //build list of ids string concatenated with comma                         
           accIds = accIds.removeEnd(','); 

      public PageReference redirectToLC(){
            String returnUrl = '/lightning/cmp/c__ProcessListView?c__listofAccounts='+accIds;
            PageReference pgReturnPage = new PageReference(returnUrl);
            return pgReturnPage;


Custom button Create a custom list button with content source "Visualforce" and enable option "Display Checkboxes (for Multi-Record Selection)". Choose the visualforce page created above

Lightning component

<aura:component implements="lightning:isUrlAddressable">
    <aura:attribute name="listofAccounts" type="List" />
    <aura:handler name="init" value="{!this}" action="{!c.onPageReferenceChange}"/>
    <lightning:card title="Account List">
        <aura:iteration items="{!v.listofAccounts}" var="item">
            <p class="slds-p-horizontal_small"> Account Id {!item} </p>


    onPageReferenceChange: function(cmp, evt, helper) {
        var myPageRef = cmp.get("v.pageReference");
        var accs = myPageRef.state.c__listofAccounts;
        //split the account ids by comma and continue logic

You can also achieve the same functionality by embedding the Lightning component on the VF Page.

Set the Values in the VF page Controller in the variable and pass the values on the Lightning Component and that gets stored in the Attributes of the Lightning COmponent.

Then and there u can use it without any much changes

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.