0

I created a custom object and assigns queue to it. And created different list views for each queue. It was doing fine in Salesforce classic the "accept" button and "change owner" is there which are OOB and working perfectly. However, When I switch to lightning the two buttons "accept" and "change owner" are not there. Is there a way to make it visible in the lightning page ?

2 Answers 2

1

What you want are lightning mass actions, which aren't available and currently slated for "future" release on the roadmap. You can achieve the same result by developing a basic Visualforce page with an extension class, configure a list button, and add the button to the object's list views Search Layout setting. For the "accept" scenario, you would first write an apex class like:

public class CaseAcceptOwnershipExtension {
     PageReference cancel;
     Case[] cases;
     public CaseAcceptOwnershipExtension(ApexPages.StandardSetController ctrl) {
          cases = (Case[])ctrl.getSelected();
          cancel = ctrl.cancel();
     }
     public PageReference updateCases() {
          for(Case c : cases) {
               c.OwnerId = UserInfo.getUserId();
          }
          update cases;
          return cancel.setRedirect(true);
     }
}

Then you'd write an empty Visualforce page that calls the apex class to execute the logic:

<apex:page standardController="Case" recordSetVar="cases"
           extensions="CaseAcceptOwnershipExtension" action="{!updateCases}"></apex:page>

Once you have finished coding, go to Setup | Customize | Cases | Buttons, Links, and Actions and click New Button or Link. Configure a List Button with checkboxes enabled, Content Source set to Visualforce, and select the Visualforce page you created for the Content. Click Save. Then go to Setup | Customize | Cases | Search Layouts and edit Cases List View to include your new button.

You will now see the button available for Case list views in Lightning Experience.

Please keep in mind that the above code will execute irrespective of user permissions and security. To include security checks like record accessibility and user permissions, use the below class:

public with sharing class CaseAcceptOwnershipExtension {

    PageReference cancel;
    Case[] cases;

    public CaseAcceptOwnershipExtension(ApexPages.StandardSetController ctrl) {
        // Return the list of sObjects that have been selected
        cases = (Case[])ctrl.getSelected();
        cancel = ctrl.cancel();
    }    

    public PageReference updateCases() {
        // Check if running user has "Transfer Record" permission
        List<PermissionSetAssignment> psa = [SELECT Id, AssigneeId, PermissionSet.IsOwnedByProfile
                                             FROM PermissionSetAssignment
                                             WHERE (PermissionSet.PermissionsTransferAnyEntity = true OR 
                                             PermissionSet.PermissionsTransferAnyCase = true)
                                             AND Assignee.IsActive = true AND AssigneeId =: UserInfo.getUserId()];
        // Create a map of Ids for the selected records
        Map<Id,Case> casesSelected = new Map<Id,Case>([SELECT Id FROM Case WHERE Id =: cases]); 
        System.debug('=== all keys in the map: ' + casesSelected.keySet());
        System.debug('=== all values in the map (as a List): ' + casesSelected.values());                
        // Any queue members or users higher in a role hierarchy can take ownership of records in a queue
        Map<Id,UserRecordAccess> ura = new Map<Id,UserRecordAccess>();
        for(UserRecordAccess a : [SELECT RecordId
                                  FROM UserRecordAccess
                                  WHERE UserId =: UserInfo.getUserId() 
                                  AND RecordId IN: casesSelected.keySet() AND HasTransferAccess = true]) {
            ura.put(a.RecordId, a);
        }
        System.debug('=== all keys in the map: ' + ura.keySet());
        System.debug('=== all values in the map (as a List): ' + ura.values());
        // If user has "Transfer Record/Case" permission OR HasTransferAccess = true, then update OwnerId                                              
        for(Case c : cases) {
            if(psa.size()>0 || ura.containsKey(c.Id)) { 
                // Assign OwnerId to running user's userId
                c.OwnerId = UserInfo.getUserId();
                c.Status = 'Accepted';
            }            
        }
        // DML operation outside of for loop
        update cases;
        // Navigate back to list view and not display the visualforce page
        return cancel.setRedirect(true);
    }

}
0

It is possible to do it be means of Quick Action to show up on Lightning

By default, in the Lightning mode Accept, Change Owner buttons are not visible which are usually getting displayed in Classic.

This trailhead will help you in solving it

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.