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.
/lightning/cmp/c__TestURLfor?c__listofAccounts={!GETRECORDIDS($ObjectType.Account)}
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 :
Cmp:
<aura:component implements="lightning:isUrlAddressable">
> <aura:attribute name="listofAccounts" type="List" />
> <aura:handler name="init" value="{!this}" action="{!c.onPageReferenceChange}"/>
> {!v.listofAccounts[0]}.
</aura:component>
Controller :
({
onPageReferenceChange: function(cmp, evt, helper) {
var pageRef = cmp.get("v.pageReference");
var listofAccounts = myPageRef.state.c__listofAccounts;
cmp.set("v.listofAccounts", listofAccounts);
console.log('listofAccounts',listofAccounts);
}
})
I get this error whenever I click the List view custom URL button
"Invalid request, post must use JSON"
Best Answer
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
Extension apex class
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
Controller.js