4

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

1 Answer 1

3

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

9
  • 1
    Thanks Rajesh! So to confirm, writing a Visualforce page that extends a StandardSetController (and uses the getSelected method to obtain the list view selection), wiring that up to a custom Visualforce button, will in Lightning Experience (Summer '18) allow the GETRECORDIDS logic to be achieved? Cool.
    – Keith C
    Jun 27, 2018 at 12:05
  • @keith c Yes. That’s exactly what it should do. Selected is the GETRECORDIDS so its up to you on what manipulations you wanted to do with those id’s. Like for example use them in apex like in the second example with a extension controler and perform any dmls. I was able to use my design both in classic and lightning seamlessly. Jun 27, 2018 at 12:12
  • Excellent. I presume though that the list view is replaced by the VFP and you have to be careful to navigate back to the list view after the VFP has finished?
    – Keith C
    Jun 27, 2018 at 12:14
  • Actually we are not replacing the list view here, rather create a list view button that is just a button like your classic javascript but instead od js you have it replaced with Vfpage. Sorry i was on my way to the commute so im using my mobile here. I can give you more details little later. But to the second point about being careful, yes based on the behavior we might need to be careful. Jun 27, 2018 at 12:21
  • 1
    No problem, feel free to comment later. The point of my comment is that I presume the VFP replaces the list view part of the Lightning Experience page so when the VFP has finished it somehow needs to navigate back to the Lightning Experience list view.
    – Keith C
    Jun 27, 2018 at 12:24

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .