[SalesForce] How to convert mass actions on list view records from Classic to Lightning Experience

We have multiple JavaScript buttons that follow this pattern where the set of checked records in a list view are first checked and then a server side operation is applied to them:

{!REQUIRESCRIPT('/soap/ajax/25.0/connection.js')}
{!REQUIRESCRIPT('/soap/ajax/25.0/apex.js')}

var ids = {!GETRECORDIDS($ObjectType.Claim__c)};
if (ids.length > 0) {
    var result = sforce.apex.execute('cve.ClaimActions', 'updateBenefitSummary', {claimIds: ids});
    if ('success' == result) {
        // See the changes
        window.location.reload();
    } else {
        // See the error message
        alert(result);
    }
} else {
    alert('Select at least one Claim first using the checkboxes');
}

Such buttons are no longer rendered in Lightning Experience and so require rework if "Lightning Ready" status is to be maintained.

My reading of this Trailhead Use Quick Actions, Custom Buttons, or Apex is that to create a Lightning Experience alternative, somewhat counter-intuitively a Visualforce page is the only solution.

Two related questions:

  • Is Visualforce the only way to go?
  • The Trailhead example does not illustrate how Visualforce can obtain the selected record Ids (some equivalent of GETRECORDIDS) from the Lightning list view. How is that done? (Based on some Googling, I'm starting to suspect that there is no solution…)

Best Answer

You could use Visualforce with standard list controller. Using a standard list controller is very similar to using a standard controller. First you set the standardController attribute on the component, then you set the recordSetVar attribute on the same component.

For example, to associate a page with the standard list controller for accounts, use the following markup:

<apex:page standardController="Account" recordSetVar="accounts">

The recordSetVar attribute not only indicates that the page uses a list controller, it sets the variable name of the record collection. This variable can be used to access data in the record collection.

Below is stack exchange link for one use case where im selecting a list of records on the list view and iterating on them to export into excel in the below example.

Note: even though the below link is for a different issue I just wanted to show you the use case. Issues with List API in Read Only mode VF page

Im my above example value="{!selected}" is the equivalent for GETRECORDIDS.

Also to get the selected record id's in apex I'm pointing here for another SFSE link Creating a custom list-view button that handles multi-record selection

I tested my vf code in lightning and it had a weird bug before summer 18 where the the selected records were inconsistent but they fixed it with summer 18 and everything looks good now. I will update here with the link when I get the chance.

Option 2: I know flow's are not as flexible as apex but you could give it a shot too based on what you are trying to achieve. Below is a link from Andrew Facet blog about leveraging flow Visual Flow with List View and Related List Buttons