Merge Mappings From Custom Programming

Generate a Document

If you're looking a way to trigger the merge of a specific mapping from code in your Org, we've built a global namespace that allows you to merge documents from anywhere inside your SFDC instance.  Here is what the function looks like:

Boolean WebmergeGenerator.generateDocument(
    String webmergeMappingId, 
    String salesforceRecordId, 
    String salesforceObjectName
);


As you can see from the definition above, you need to pass along the Mapping ID, the Record ID, and the name of the Object.  With these 3 parameters, we can automatically trigger the merge. 

Here is an example of what this might look like in your Salesforce APEX code.

Boolean mergeSuccess = webm.WebmergeGenerator.generateDocument(
    'XYZ00000001234', 
    'ABC00000000123', 
    'Account'
);

 

Preview a Document

If you're looking a way to trigger the preview for a specific mapping, you can use previewDocument(). Here is what the function looks like:

String WebmergeGenerator.previewDocument(
    String webmergeMappingId, 
    String salesforceRecordId, 
    String salesforceObjectName
);


As you can see from the definition above, you need to pass along the Mapping ID, the Record ID, and the name of the Object. With these 3 parameters, we can automatically trigger the preview.

Here is an example of what this might look like in your Salesforce APEX code.

String fileURL = webm.WebmergeGenerator.previewDocument(
    'XYZ00000001234', 
    'ABC00000000123', 
    'Account'
);

 

Get Generated Document Attachments

If you're looking for a way to get a list of the documents that were created, you can use the following function:

List<Attachment> WebmergeGenerator.generateDocumentGetAttachments(
    String webmergeMappingId, 
    String salesforceRecordId, 
    String salesforceObjectName
);


This function returns a list of attachments (even if there is only 1 attachment, it still returns a list) that have been created (but not inserted/committed) for the record.

Here is an example of what this might look like in your Salesforce APEX code.

List<Attachment> generatedAttachments = webm.WebmergeGenerator.generateDocumentGetAttachments(
    'XYZ00000001234', 
    'ABC00000000123', 
    'Account'
);

 

Generate Documents in Batch

If you're looking for a way to generate multiple documents in batch (for example, from a list view), you can use this function:

Boolean generateDocumentBatch(
    String webmergeMappingId, 
    List<String> salesforceRecordIds, 
    String salesforceObjectName
);


This function returns a boolean true/false base on the success of creating the batch.

Here is an example of what this might look like in your Salesforce APEX code.

 

List<String> sfRecords = new List<String> {'ABC00000000123', 'ABC00000000789'}; 
Boolean success = webm.WebmergeGenerator.generateDocumentBatch(
    'XYZ00000001234', 
    sfRecords, 
    'Account'
);

 

Generate Batch Combined PDF

If you're looking for a way to generate multiple documents in batch and combine them into a single PDF, you can use this function:

Boolean generateDocumentBatchCombined(
    String webmergeMappingId, 
    List<String> salesforceRecordIds, 
    String salesforceObjectName
);


This function returns a boolean true/false base on the success of creating the batch.

Here is an example of what this might look like in your Salesforce APEX code.

List<String> sfRecords = new List<String> {'ABC00000000123', 'ABC00000000789'}; 
Boolean success = webm.WebmergeGenerator.generateDocumentBatchCombined(
    'XYZ00000001234', 
    sfRecords, 
    'Account'
);

 

Merge Document without Mapping

If you're looking for a way to send data over to WebMerge to merge into a document (without a mapping), you can use this function:

HttpResponse doMerge(
    Map<String, String> mergeData,
    String mergeUrl
);


This function returns the HttpResponse from the merge request. You can save the file/response from there.

Here is an example of what this might look like in your Salesforce APEX code.

Map<String, String> mergeData = new Map<String, String>{};
mergeData.put('Name', 'John Smith');
mergeData.put('Phone', '434-555-3499');
HttpResponse response = webm.WebmergeGenerator.doMerge(
    mergeData, 
    'https://www.webmerge.me/merge/12345/abcdef'
);

 

Merge JSON Data

You can also use JSON to send data over to your WebMerge document:

HttpResponse doMerge(
    String jsonString,
    String mergeUrl
);

 

Here is an example of what this might look like in your Salesforce APEX code.

String jsonString = '{"Name":"John Smith", "Phone":"434-555-3499"}';
HttpResponse response = webm.WebmergeGenerator.doMerge(
    jsonString, 
    'https://www.webmerge.me/merge/12345/abcdef'
);

 

Preview Document

You can also preview a merge using doPreview() instead of doMerge():

HttpResponse doPreview(
    Map<String, String> mergeData,
    String mergeUrl
);

HttpResponse doPreview(
String jsonString,
String mergeUrl
);

 

Merge Report Data

If you're looking for a way to send report data over to WebMerge to merge into a document, you can use this function:

Boolean mergeReport(
    String reportId,
    String mergeUrl
);


This function returns a boolean true/false base on the success of creating the merge.

Here is an example of what this might look like in your Salesforce APEX code.

Boolean success = webm.WebmergeGenerator.mergeReport(
    'RRR00000001234', 
    'https://www.webmerge.me/merge/12345/abcdef'
);
Have more questions? Submit a request

12 Comments

  • Avatar
    Steve Jones

    I've been successfully using generateDocumentBatch, and want to try producing a single pdf using generateDocumentBatchCombined.
    When I try it however I don't see any merge. I'm using a data route which is adding a coversheet and delivering to Dropbox. I've tried test mode on and off. Salesforce is logging batch apex activity as normal, but there's no record of a merge in the Data Route overview and no document is produced.

  • Avatar
    Jeremy Clarke

    Hi Steve,

    Please submit a support ticket and we'll help you from there!

    Thanks :)

  • Avatar
    Muriel DENAIS

    Hi, I'm getting the following error when my batch is running :
    First error: webm:Too many SOQL queries: 201

    Where can I define the batch size, please ?

  • Avatar
    Jeremy Clarke

    Hi Muriel,

    Can you create a support ticket and send us a snippet of your code so we can see what you're doing?

    Thanks!

  • Avatar
    Pradnya Desai

    Hi Jeremy,

    How can we use One document to generateDocument and Generate preview.
    Do you have 'generatePreview' method?

    Thanks.

  • Avatar
    Jeremy Clarke

    Hi Pradnya,

    We have added a function called previewDocument() to the package (version 1.199). Please install the latest version of our managed package from the AppExchange and you can find details of previewDocument() above.

    Thanks!

  • Avatar
    Connor Giles

    Hi Jeremy,

    If we use generateDocumentBatchCombined() is there a way to then get the result of that PDF in code or do we need to use a delivery option for that?

    Thanks!

  • Avatar
    Jeremy Clarke

    Hi Connor,

    Unfortunately, you'll need to use a delivery option for documents generated in Batch.

    Thanks!

  • Avatar
    Pradnya Desai

    Hi Jeremy,
    How can we send email for the document generated using previewDocument method.

    Thanks,
    Pradnya

  • Avatar
    Jeremy Clarke

    Hi Pradnya,

    Unfortunately, there isn't a way to send an email from the previewDocument method because it's meant to be a real-time preview. You'll need to use the mergeDocument method instead to trigger the email delivery you have setup on the document.

    Thanks!

  • Avatar
    Pradnya Desai

    Hi Jeremy,
    Is there any way to generate document in Draft mode.

    Thanks,
    Pradnya

  • Avatar
    Jeremy Clarke

    Hi Pradnya,

    Unfortunately, the only option is to use the doMerge() method where you can provide the Merge URL to the document and you can add "?test=1" parameter to the URL. This will merge the document in test mode and still send the email deliveries.

Please sign in to leave a comment.
Powered by Zendesk