Generate Documents from List View

In the WebMerge Managed Package (versions 1.250+), we have built-in buttons for generating documents from a List View for Account, Contact, Lead, and Opportunity objects. For those objects, simply open up your Search Page (List View) Layout and add the WebMerge button to the page.

From your List View, you'll be able to select a set of records, click the WebMerge button, then you'll be asked to pick your WebMerge Mapping (just like when you're merging a single record)

Setup VF Page & Button for Custom Objects

1. Setup a new Visualforce Page under Setup > Develop > Visualforce Pages

Use this code for the page (change "Certificate__c" to match your object name):

<apex:page standardController="Certificate__c" extensions="webm.WebmergeWizardController" docType="html-5.0" title="Webmerge List View Merge" recordSetVar="selectedRecords">
<webm:WebMergeMassMerge records="{!selectedRecords}" />
</apex:page>


2. Create a new List View Button for your object and select the VF page you just created.

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

- Content Source: Visualforce Page

 

new_list_button.png

 

3. Add your new button to your Search 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.

list_view_layout.png

 

 


List View in Classic (via Javascript Button)

*This is old functionality that is only available in Classic

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

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:

{!REQUIRESCRIPT("/soap/ajax/36.0/connection.js")}
{!REQUIRESCRIPT("/soap/ajax/36.0/apex.js")}
var records = {!GETRECORDIDS($ObjectType.Account)};
sforce.apex.execute("webm.WebmergeGenerator", "generateDocumentBatchJS", {
    wmMappingId:"a01i000000aWmw5AAC",
    sfObjectIds: records,
    sfObjectName:"Account"
});
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 your page 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:

{!REQUIRESCRIPT("/soap/ajax/29.0/connection.js")}
{!REQUIRESCRIPT("/soap/ajax/29.0/apex.js")}
{!REQUIRESCRIPT("https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js")}
var records = {!GETRECORDIDS($ObjectType.Account)};

var accounts = sforce.connection.retrieve('Id,Name,Phone,BillingStreet', 'Account', records);
accounts = JSON.parse(JSON.stringify(accounts));
$.post('https://www.webmerge.me/merge/12345/abcdef', {'accounts':accounts});
alert('Done');
Have more questions? Submit a request

13 Comments

  • Avatar
    CH Digital

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

    Thanks,
    Corinne

    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!

    Thanks,

    Jeremy

  • 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: https://support.webmerge.me/hc/en-us/articles/206527256-Merge-Mappings-From-Custom-Programming (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.)
    Thanks,
    Katrina.

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

    Thanks!

  • Avatar
    Katrina Fisher

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

  • Avatar
    HARSHAVARDHAN Y R

    I'm getting error while saving the below code in VF Page

     <apex:page standardController="Account" extensions="webm.WebmergeWizardController" docType="html-5.0" title="Webmerge List View Merge" recordSetVar="selectedRecords">
    <webm:WebMergeMassMerge records="{!selectedRecords}" />
    </apex:page>

    The installed managed class webm.WebmergeWizardController is not visible

    Edited by HARSHAVARDHAN Y R
  • Avatar
    Saraswathi D

    Hi Jeremy,

    I was trying to save the below apex page

    But i'm getting below error
    The installed managed class webm.WebmergeWizardController is not visible

    webm is the managed package,

    If i remove the webm. then it showing below error message
    Apex class 'WebmergeWizardController' does not exist

    Thanks

  • Avatar
    Jeremy Clarke

    Hi Saraswathi,

    This issue (not being visible) should be fixed in version 1.251 -- can you please try to update to the latest version from the AppExchange?

    Thanks!

    Edited by Jeremy Clarke
  • Avatar
    Saraswathi D

    Thanks

    I will check and let you know.

Please sign in to leave a comment.
Powered by Zendesk