Add Support for Salesforce and Custom Objects

After you’ve logged into WebMerge, click the WebMerge Settings tab.




Here you can add or remove support for various Salesforce objects.  These are the primary objects that you want to be able to merge data from.  Feel free to add any of your standard or custom objects.

Adding Merge Buttons for other Salesforce Objects

WebMerge for Salesforce works with a few standard Salesforce Objects out of the box. If you’d like to add more, you can do so.

  • Create a new Visualforce Page
    • Go to Setup > Develop > Visualforce Pages
    • Click the New button
    • Add your page code. Set the standardController property on the page to be the object you’d like to add support for. Also add the docType and optionally add your own title. In the following example, we are displaying the certificate name. Keep in mind that not every Salesforce object has a Name property.
      <apex:page standardController="Certificate__c" docType="html-5.0" title="Webmerge Certificate: {!Certificate__c.Name}">
          <webm:WebmergeWizard record="{!Certificate__c}" />
    • *Note: if you are receiving Apex errors about missing columns, please check your Version Settings and go back a few versions for your Salesforce API version (try version 29.0 first).
    • *Optional:  If you would like to auto-select a mapping, you can add a "mappingId" parameter to your VF page code to send the Mapping ID to the VF page: <webm:WebmergeWizard record="{!Certificate__c}" mappingId="0x0000002384dbna" />
    • *Optional: If your object doesn't have a "Name" field, you will need to add a "nameField" parameter to your page code to tell the system what field to use instead of Name.  Like this: <webm:WebmergeWizard record="{!Certificate__c}" nameField="Certificate_Id__c" />


    • Security: Once you create the VF page, you'll need to give permissions to the User Profiles that you want to have access to this page. Under the main Visualforce Pages, click the Security link next to your page.

  • Create a new button: Set the button type to Visualforce and select your new Visualforce page.
    • Go to Setup > Create > Objects
    • Click on the object you want to create the button for
    • Under the Buttons, Links, and Actions section, click New Button or Link
    • Give the button a name and choose the Content Source to be VisualForce Page, then choose the page you just created

  • Add your new button to a Page Layout
    • Go to the Detail page for your object, and click the Edit Layout link
    • Choose Buttons from the left side and then drag your newly created button onto your layout, and save.


Adding Apex Triggers for other Salesforce Objects

You only need to take this step if you need plan on automatically generating documents when a record is inserted/updated. If you are just clicking the buttons, you don't need to worry about the triggers.

**Note: You can now use the Process Builder to automatically generate documents. You do not need to use this functionality anymore. See:

  • Install WebMerge: If you have not installed the WebMerge Managed Package in your sandbox, please do that first.

  • Create a new Apex Trigger: Select the Salesforce Object you’d like to trigger on and select After Insert and After Update only. Do not set any other values for this.

  • Add the Apex Trigger code: Add the following code snippet to your new Apex Trigger.

    trigger TriggerName on ObjectName (after insert, after update) { new
        webm.WebmergeTriggerEvaluator(, Trigger.old).doTrigger(); 

    For the Invoice object, the trigger would look like this:

    trigger MyInvoiceTrigger on Invoice__c (after insert, after update) { 
        new webm.WebmergeTriggerEvaluator(, Trigger.old).doTrigger(); 
  • Setup Test Class: Salesforce requires you to have test classes for code coverage, so we'll need to add a test class under Setup > Develop > Apex Classes. Copy and paste the code below into your new class file, then update the object name to match your object (ie in our example we're using Invoice__c)

    private with sharing class TriggerTests
        static testMethod void invoiceTests()
            List<webm__Webmerge_Mapping__c> mappings = [Select Id from webm__Webmerge_Mapping__c LIMIT 1000];
            delete mappings;
        webm__Webmerge_Mapping__c mapping0        = new webm__Webmerge_Mapping__c();
        webm__Webmerge_Mapping__c mapping1        = new webm__Webmerge_Mapping__c();
        Invoice__c          obj         = new Invoice__c();
        obj.Name                    = 'Bob';
        mapping0.webm__Active__c              = true;
        mapping0.webm__Evaluation_Criteria__c         = 'created, and every time it\'s edited';   
        mapping0.webm__Salesforce_Object_Name__c      = 'Invoice__c';
        mapping0.webm__Autogenerate__c            = true;
        mapping1.webm__Active__c              = true;
        mapping1.webm__Evaluation_Criteria__c         = 'created, and any time it\'s edited to subsequently meet criteria';
        mapping1.webm__Salesforce_Object_Name__c      = 'Invoice__c';
        mapping1.webm__Autogenerate__c            = true;
        insert new List<webm__Webmerge_Mapping__c> {mapping0, mapping1};
        webm__Field_Mapping__c fieldMap0      = new webm__Field_Mapping__c();
        fieldMap0.webm__Webmerge_Field_Id__c      = '1233';
        fieldMap0.webm__Webmerge_Field_Name__c    = 'CompanyName';
        fieldMap0.webm__Salesforce_Field_Name__c  = 'Name';
        fieldMap0.webm__Salesforce_Field_Id__c    = 'Name';
        fieldMap0.webm__Webmerge_Mapping__c       = mapping0.Id;
        webm__Field_Mapping__c fieldMap1      = new webm__Field_Mapping__c();
        fieldMap1.webm__Webmerge_Field_Id__c      = '1233';
        fieldMap1.webm__Webmerge_Field_Name__c    = 'CompanyName';
        fieldMap1.webm__Salesforce_Field_Name__c  = 'Name';
        fieldMap1.webm__Salesforce_Field_Id__c    = 'Name';
        fieldMap1.webm__Webmerge_Mapping__c       = mapping1.Id;
        insert new List<webm__Field_Mapping__c> {fieldMap0, fieldMap1};
        webm__Webmerge_Mapping_Criteria__c    crit0 = new webm__Webmerge_Mapping_Criteria__c();
        webm__Webmerge_Mapping_Criteria__c    crit1 = new webm__Webmerge_Mapping_Criteria__c();
        crit0.webm__Field__c          = 'Name';
        crit0.webm__Operator__c       = 'equals';
        crit0.webm__Value__c          = 'Steve';
        crit0.webm__Webmerge_Mapping__c   = mapping0.Id;
        crit1.webm__Field__c          = 'Name';
        crit1.webm__Operator__c       = 'equals';
        crit1.webm__Value__c          = 'Bob';
        crit1.webm__Webmerge_Mapping__c   = mapping1.Id;
        insert new List<webm__Webmerge_Mapping_Criteria__c>{crit0, crit1};
        insert obj;
        obj = [SELECT Id, Name FROM Invoice__c WHERE Id = :obj.Id LIMIT 1];
        obj.Name = 'Steve';
        update obj;
Have more questions? Submit a request


  • Avatar
    Saraswathi D

    I want to add the merge information(attachment information) to the Custom Object after the merge.
    How to do i get the information in the triggers ?

    Thanks in advance

  • Avatar
    Jeremy Clarke

    Hi Saraswathi,

    That setting is actually handled in your WebMerge Mapping. Please click the "Save in Attachments" option under Optional Settings.


Please sign in to leave a comment.
Powered by Zendesk