Implementing WebMerge for Salesforce Using Apex

Implementing WebMerge for Salesforce Using Apex

Webmerge is used to Customize and Automate Your Document Generation. It is an online service that self-operating your document creation process. It helps to create customized PDF and Word documents for contracts, applications, government forms, and more.


Delivery is also a walk in the part as users can choice a third-party integration to send or attach documents in Salesforce or anywhere.

Why Webmerge?

As we know the Document management system for Salesforce is becoming imperious to operations in an array of industries. It manages its sales lifecycle with greater ability. In terms of Salesforce, it has integrated with most of the different document management system platforms for the mastery of the paperless office and the sales cycles its solution facilitates.

There is multiple document management system apps are available for Salesforce, but Webmerge has some tremendous features as discussed below:


Few key points for Webmerge are the following :

  • Need to verify in salesforce org with key and secret to access Webmerge services.
  • Logic / conditional text in templates
  • Unlimited Max templates per setup
  • External API for integrations support
  • HTML Document Builder
  • Easy Data Routing
  • Support Document generation for multiple records through Apex

Steps to process multiple records in a single request Using Salesforce Apex:

One of the best things about using Webmerge is this ability to process multiple records at a time using apex or javascript.

Please follow the mentioned steps to achieve this:

  • Step 1 - Go to the Setup -> Installed Packages -> Webmerge
  • Step 2 - Click on ‘View Components’
  • Step 3 - Search for ‘WebmergeGenerator’ Apex class and click on that.
  • Step 4 - Under this class search for ‘generateDocumentBatchJS’ static method and its parameter properties.
  • Step 5 - After taking this class and its method reference, now create an apex class whom we process multiple records at a time.
  • Step 6 - Go to Setup -> In Quick Find / Search type ‘Apex classes’ -> Click on ‘New’, and create a new class with the following code.
//This class used to processed multiple records at a time in Webmerge.
public class WebmergeBulkRecordProcessed {
    public static void goRecordsToProcess() {
        try {
            List <id> recordsIds = new List <id>();
            for(Contact objCon : [Select Id,LastName,Email,Phone,Asst_Email__c from Contact Limit 10]) {
            if(!recordsIds.isEmpty()) {
                //for only POC purpose used hardcoded id of mapping record.
        } catch(Exception e) {
            System.debug('Exception type caught: ' + e.getTypeName()); System.debug('Message: ' + e.getMessage()); System.debug('Line number: ' + e.getLineNumber());

To find the “Mapping ID” (‘a6H0U0000004EWWUA2’), 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 “Contact”) to match your object type.

Step 7 - You may execute this class to process queryable records into Webmerge by using Developer console -> Anonymous Window.


Now you analyze all selected records that are processed successfully.

Thank you!

Popular Salesforce Blogs