In the Formstack Documents Managed Package (versions 1.250+), you can utilize the built-in buttons to generate documents from a List View for Account, Contact, Lead, and Opportunity objects.
Add List View for Standard Objects
To add, simply open up your Search Page (List View) Layout and add the Formstack Documents button to the page for standard objects: Account, Contact, Lead, and Opportunity.
From your List View, you will then be able to select a set of records. Click the Formstack Documents button and pick your Formstack Mapping (just like when you're merging a single record).
Set up Visualforce Page and 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}" combine="false" />
</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 Custom Object, 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
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.
Combine Attribute with List View
In the Visualforce element, combine the documents into one using combine="true." It will look like:
<webm:WebMergeMassMerge records="{!selectedRecords}" combine="true" />
Please note - The Immediately Download option does not work when using a List View merge (when doing asynchronous or batch merges) to download multiple documents at the same time.
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');Note: In the statement above, the first argument of 'accounts' to the left of the : refers to the merge field on your document template that will be receiving the array of data. The second argument to the right of the : refers to the variable defined in the Javascript snippet.
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 Formstack 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)
Why is my list view merges not showing as processing in Overview?
When list views are used to merge documents, it does so in a batch job. A list of records is passed through a batch process that works through the jobs asynchronously.