Salesforce Integration with PandaDoc – Part 1a: Adding PandaDoc module to Custom Objects in Salesforce

Focus: The focus of this document is to provide you steps on how to install the PandaDoc module into custom objects in Salesforce.

If you have not gone through the installation of PandaDoc into Salesforce, please click here and follow all steps.

If you created a “Custom Object” in Salesforce and you want to add the PandaDoc module to it, you will need go through the steps for each Custom Object. (Click here to learn how to create a Custom Object within Salesforce)

Salesforce Versions for Custom Objects: You will need Salesforce: “Enterprise”, “Unlimited”, or “Developer edition”. Salesforce Pro does not offer access to APEX classes and are unable to use custom objects with this integration.

Step 1: Create or Access Your Salesforce Custom Object

Step 1a: Go to Setup -> Build -> Create -> Objects

SFDC - Custom Objectss -1 SFDC - Custom Objectss -2

Step 1b: Select your Custom Object or create a new one by clicking “New Custom Object”.

SFDC - Custom Objectss -3

Step 2: Create a Fieldset for the Custom Object

Step 2a: Scroll down to the section “Field Sets” and select “New” to create a new Field Set for the Custom Object.

SFDC - Custom Objectss -4

Step 2b: Enter the Field Set information as follows and select “Save”:

  • Field Set Label: OBJECTNAME_PANDADOC
  • Field Set Name: OBJECTNAME_PANDADOC

For this example, we’ll create a Custom Object called “Service City”, representing an area a business provides services in. We might have documents to store for operations in each area.

SFDC - Custom Objectss -5

Step 2c: Save the Field Set

SFDC - Custom Objectss -6

Step 3: Create Custom JSON Builder for Custom Object

PandaDoc will look for a custom JSON builder for your custom object to serialize the Custom Object’s data and pass it to PandaDoc when you create a document from your Custom Object’s page.

Step 3a: From the Salesforce Developer Console or your own IDE software, create a new Apex Class with the following parameters.

SFDC - Custom Objectss -7 SFDC - Custom Objectss -8

Name: CustomObjectNameJsonBuilder (Example: ServiceCityJsonBuilder)

SFDC - Custom Objectss -9

Global scope and extends pandadoc.JsonBuilder

SFDC - Custom Objectss -10

Default constructor with no parameters.

SFDC - Custom Objectss -11

You should call a parent’s constructor in your default constructor and pass 2 arguments there:

  • Schema.sObjectType of an object which you’re building JsonBuilder for (you can get it via [sObjectName].getSobjectType())
  • Map<String, Set<String>> – a Map where you define nested objects you want to add to JSON. Key is a name of child relation and value is a list of fields from child relation object. You can pass null, if you don’t need to configure child relations. (Start with null and extend later).
SFDC - Custom Objectss -12

JsonBuilder should implement all abstract methods of a base class. If you don’t need this information, please return null.

  • Recipients: global abstract List<Recipient> getRecipients(sObject record); – returns a list of recipients from a custom object (will be prepopulated in PandaDoc);
  • Items (Pricing Table Items): global abstract List<Item> getItems(sObject record); – returns a list of products (pricing table items, will be prepopulated in PandaDoc).
SFDC - Custom Objectss -13

Leaving Recipients and Items as null will work to get started. However if you wish to provide Recipients or Items, here is the format hard coded as Strings:

SFDC - Custom Objectss -14

Here’s a gist link to copy and paste any JsonBuilder code: https://gist.github.com/btskyy/16c36f3ec46172c891e9a3f07fde9a1b

Step 4: Add the created JsonBuilder Class to a Json Builder Factory

Step 4a: Go to PandaDoc custom settings and open “PandaDoc JsonBuilder Mapping”

SFDC - Custom Objectss -15

Step 4b: Select “Manage” to manage the custom mappings.

SFDC - Custom Objectss -16

Step 4c: Select “New” to add the new JsonBuilder mapping

SFDC - Custom Objectss -17

Step 4d: Add an entry where: name is custom object API name with a namespace and JsonBuilder Class Name – custom JsonBuilder class name with a namespace (e.g. pandadoc.ServiceCityJsonBuilder)

SFDC - Custom Objectss -18

Step 5: Create a VisualForce Page for the Custom Object

To embed the PandaDoc module your custom object pages, you will need to create a VisualForce component and add it to custom object’s page layout.

Step 5a: Go to Setup -> Develop -> Visualforce Pages and click on “New” to add a new Visualforce page.

SFDC - Custom Objectss -19

Step 5b: Enter a Visualforce Label and Name for your page.

SFDC - Custom Objectss -20

Step 5c: Copy the source of this linked Visaulforce template and paste it into the “Visualforce Markup” section of the page settings: https://gist.github.com/btskyy/1ceb181f4365beb104f4468226e45d82

Step 5d: Replace the following values in the template with your controller name:

  • Line 1: StandardController="CUSTOM_OBJECT_API_NAME"
  • Line 24: ObjectId={!CUSTOM_OBJECT_API_NAME.Id}
SFDC - Custom Objectss -21

Step 5e: Save the Visualforce page.

SFDC - Custom Objectss -22

Step 6: Insert the Visualforce page into your Custom Object view.

Step 6a: Go to Setup -> Create -> Custom Objects, and select your Custom Object from the list of Custom Objects.

SFDC - Custom Objectss -2

Step 6b: Scroll down to “Page Layouts” and select “Edit” to edit your Custom Object’s page layout.

SFDC - Custom Objectss -23

Step 6c: From “Fields” select “Section” and drag a new section into your page layout.

SFDC - Custom Objectss -24

Step 6d: Be sure to name the section and select a 1-Column layout. Then select “OK”.

SFDC - Custom Objectss -25

Step 6e: From “Visualforce Pages” select your Custom Object Visualforce Page and drag the page into the Section you just created.

SFDC - Custom Objectss -26

Step 6f: Save the layout.

SFDC - Custom Objectss -27

Step 7: Finished

Your Custom Object layout will now have PandaDoc documents in the view that are associated with each Custom Object record.

SFDC - Custom Objectss -28

Have questions? For faster support please:

  1. Log in to PandaDoc
  2. Click on the “Help” button next to your profile icon
  3. Choose Submit Help Request option

Or feel free to contact us using our public form:

Contact Support