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'
);

 

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

4 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!

Please sign in to leave a comment.
Powered by Zendesk