Generate Documents from List View

In addition to generating documents from specific records in Salesforce, you can also generate documents from a List View of records.  To do this, you'll need to:

1. Setup a List View button

Standard Object: Under Setup > Customize, pick the object you want to add the button to and go to the Buttons, Links and Actions page. 

Custom Object: Under Setup > Create > Objects, pick the object that you want to create the button for and scroll down to the Buttons, Links, and Actions section.

Go ahead and create new button. 

- Type: List View Button

- Behavior: Execute Javascript


2. Add Javascript for the button

To trigger the merge, you'll need to add this javascript:

var records = {!GETRECORDIDS($ObjectType.Account)};
sforce.apex.execute("webm.WebmergeGenerator", "generateDocumentBatchJS", {
    sfObjectIds: records,
alert('The documents have been generated!');

To find the "Mapping ID" (wmMappingId), open up the WebMerge Mappings tab and Edit one of your mappings.  In the URL of the page, you'll find the ID you need to use.  Make sure to edit the Object Name (ie "Account") to match your object type.



3. Add button to the Page Layout

To add your button to the List View page, open up your Search Layouts and then find the List View layout.  Click edit and you'll see an option to add your button to the layout.



Other Available Functions

  • generateDocumentJS(wmMappingId, sfObjectId, sfObjectName)
  • generateDocumentBatchJS(wmMappingId, sfObjectIds, sfObjectName)
  • generateDocumentBatchCombinedJS(wmMappingId, sfObjectIds, sfObjectName)



Send Data to Same Document

If you'd like to send all records to the same document, you can setup javascript to send over the data directly to your document (without needing a Mapping) like this:

var records = {!GETRECORDIDS($ObjectType.Account)};

var accounts = sforce.connection.retrieve('Id,Name,Phone,BillingStreet', 'Account', records);
accounts = JSON.parse(JSON.stringify(accounts));
$.post('', {'accounts':accounts});



List View in Lightning

The javascript button will not work in Lightning, so we suggest using a combination of an action that will update a field on each record which will trigger the Process Builder for each selected record.  Here are the steps:

  1. Under Settings > Object Manager, create a custom field on your object (checkbox) that will be used to trigger the process builder
  2. Under Actions, Buttons, and Links, Create a New Action
    1. Action Type: Update a Record
    2. Customize the action to update your custom field
  3. Add the new Action to your Search Layout > List View
  4. Create a new process in the process builder that is triggered from your custom field being updated.
Have more questions? Submit a request


  • Avatar
    CH Digital

    This is a great functionality, but JS buttons are no longer supported in Lightning - do you have a workaround for that?


    Ringier AG

    Edited by CH Digital
  • Avatar
    Jeremy Clarke

    Hi Corinne,

    Unfortunately, since Lightning doesn't allow for you to select multiple records from list views anymore either, we don't have a good workaround. If you have any ideas, please let us know!



  • Avatar
    Daniel Maxwell

    Jeremy, I've seen some of the other document generation software solutions employ "generate from report" as a way to get around the list view limitation in Lightning.

    Is there any way you think that could work? (For example, create a report that shows new leads from a tradeshow. Then, you can create a welcome letter to all leads on that list). This essentially gives users the same functionality as creating from list view -- and is fully compatible with Salesforce Lightning.

    Edited by Daniel Maxwell
  • Avatar
    Jeremy Clarke

    Hi Daniel,

    Thanks for the suggestion! We have an APEX API that can be used to generate documents from Reports: (end of article)

  • Avatar
    Katrina Fisher

    Hi Jeremy,

    I am currently trialing WebMerge for a client. For the standard letters I have been very pleased.

    Linked to the conversation above, are you please able to provide instructions on how to create a WebMerge document from a Salesforce Lightning Report?

    I have a report for custom objects, which shows all the records related to a particular program within a defined date range. In Salesforce Lightning, the report has a title, a header row, rows of data followed by totals at the bottom. E.g. similar to a PDF invoice for an account - but the data is currently filtered and output by a report.

    Thanks, Katrina.

  • Avatar
    Jeremy Clarke

    Hi Katrina,

    Are you wanting to create a PDF of the actual report, or are you wanting to create a PDF document for each record that is listed on the report?

  • Avatar
    Katrina Fisher

    Hi Jeremy, I want to create one PDF report document containing all the records and totals from the report. (E.g. an activity statement that is sent to a contact, listing all the records revelevant to their specific program.)

  • Avatar
    Jeremy Clarke

    Hi Katrina,

    We don't have an out-of-the-box way to do that, but you can build a APEX process that could connect to a button and then call our APEX API mergeReport() function. Or you can use the APEX code to query the database for data from the report then use doMerge() to send the data over to WebMerge.


  • Avatar
    Katrina Fisher

    Thanks Jeremy, I’ll research these functions and see if I can get something working.

Please sign in to leave a comment.
Powered by Zendesk