Skip to main content

Topic

How to create Mass Button in Lightning
Note: The Mass DocGen Feature is required 
 

Instructions

Note: This button is a Sample for the ability to specify a contact to meet the Salesforce Contact Email validation requirement and run mass from Custom Objects in lightning.

Below is a Visualforce page sample referencing the Opportunity object in the ‘standardController’. Replace the Opportunity object with the desired object's API name.

 See Additional Customization Configurations section for additional parameters.
<apex:page standardController="Opportunity" recordSetVar="units">
<script src="/soap/ajax/26.0/connection.js"> </script>
<script src="/support/console/26.0/integration.js"> </script>
<apex:dataTable value="{!selected}" var="un">
    <apex:column >
        <apex:outputLabel styleClass="ids">{!un.Id}</apex:outputLabel>
    </apex:column>
</apex:dataTable>
<style>
.ids{visibility : hidden}
</style>
<script type="text/javascript">
    document.addEventListener("DOMContentLoaded", function(event) { 
        var elems = document.body.getElementsByClassName("ids");
        var ids = new Array();
        for (var i = elems.length - 1; i >= 0; i--) {
            ids i] = elems=i].innerHTML;    
        }
        console.log(ids);
        if (!ids || ids.length < 1)
            alert('Please select at least one record.');
        else
        {
             var instanceName = window.location.hostname;
            var newLocation = '/apex/loop__jobqueuestatus';
            console.log(instanceName+newLocation);
            var redirectUrl = '/apex/loop__masslooplus?';
 
            redirectUrl += '&recordIds='+ids.join(',');
            redirectUrl += '&sessionId={!$Api.Session_ID}';
            redirectUrl += '&retURL='+newLocation;
            if (sforce && sforce.one && sforce.one.navigateToURL) {
    sforce.one.navigateToURL(redirectUrl);
} else {
    window.location.href = redirectUrl;
}
        }
    });
</script>
</apex:page>

1. Create a new Visualforce page:
  1. Navigate to Salesforce setup
  2. Quick Find search: Visualforce Pages
  3. Click ‘New’
7547i72F519854E950E71.png

             iv. Create a unique name “MassLightning{object}”.
              v. Checkbox: ‘Available for Lightning Experience’.
             vi. Paste the sample into the ‘Visualforce Markup’ Section.
            vii. Add the desired object API name for the ‘standardController’.
           viii. Click Save.

7549i6D4EBC51188FB73C.png

 2. Create a New Button:
  1. Navigate to Salesforce Setup:
  2. Select Object from ‘Object Manager’.
  3. Select ‘Button, Links, and Actions’ section.
  4. Click New Button or Link
7551iCA4E3A5BBE6A57EB.png

3. Button Configuration:
  1. Create Label Name.
  2. Display Type: List Button with Display Checkboxes.
  3. Behavior: Select desired behavior.
  4. Content Source: Visualforce Page
  5. Content: Select the created Visualforce Page from the list.
  6. Click Save.
7553iFC6AA839D9636403.png

4. Add button to the layout:
  1. Navigate to Salesforce Setup:
  2. Select Object from ‘Object Manager’.
  3. Select ‘Search Layouts’ or 'Search Layouts for Salesforce Classic' Section.
  4. Select ‘Edit’ on the List View Layout.
7555i2A4DFBAD35E5BCEC.png
Or
7557i2D4822090979F7E8.png
  1.    v. Select the button from the ‘Available Buttons’ list.
  2.   vi. Add it to the ‘Selected Buttons’ list.
  3.  vii. Click Save.
7559i89E7C2D466042231.png

5. Executing Mass via List View:
  1. Navigate to the Object List View.
  2. Select desired records.
  3. Click the List View Button.
  4. Select DocGen Package and Delivery Option.
  5. Click Run.
7561iF3E57F823BC7CB82.png
 

Additional Information

Additional Customization Configurations:

Parameter Documentation: Click Here

Add additional parameters below the {'redirectUrl += '&sessionId={!$Api.Session_ID}';} line.

Email with Mass:
  1. If the delivery option is Email, a contact field will need to be configured in the Visualforce page.
      1. redirectUrl += “&contactfield=APINAME_OF_FIELD”;
      2. Replace the APINAME_OF_FIELD with the desired contact field API.
Specify Document Packages and Delivery Options:
  1. To specify Document Packages and Delivery Option, add the following line and parameters.
      1. redirectUrl += "&ddpIds=PACKAGE_ID&deploy=DELIVERY_ID";
      2. Replace the PACKAGE_ID & DELIVERY_ID with the desired record ids.
Run Automatically:
  1. To bypass the user selection page, add the &autorun=true parameter.
      1. redirectUrl += "&autorun=true";
7562iC9D993A1D1CB4C88.png

Redirect after generation:
By default, the Job Queue Status has been chosen to be the redirect location. 
A Salesforce Lightning List View can be chosen as an alternative. This can not be dynamic unless you wish to develop the code and button independently.

1. Navigate to the desired List View in Lightning and copy the information after the ".com". 
2. Replace /apex/loop__jobqueuestatus in line 28 of the Visualforcepage with the desired URL. See example below:

1. Get the URL:
7563i4E288CD609170BD4.png

2. Add to the Visualforce Page:
7564iAD11D7664855DED1.png

 

When I run the Mass Button I end up with light blue highlights behind the Merged Fields. However when I run the DocGen Package individually, I do not get the light blue highlights behind the Merged Fields. Does anyone else encounter this and how did you rectify?


Reply