Articles in this section

Unattended Document Generation in Salesforce Using the Public API

About this article

This article walks through Templafy's packaged Salesforce flow that utilizes Templafy's Document Generation API endpoints. The information in this article includes the necessary setup steps to utilize the packaged Salesforce flow to automate a specific template. It also includes some optional and suggested steps to accomplish different results.

Sections in this article:

Prerequisites

 
  • Admin access in Templafy tenant
  • Admin access in Salesforce
  • App Connector, Data Connector, Public API modules enabled
  • Salesforce Data Connector and Salesforce App Connector enabled

 

Configuration Steps in Templafy

  1. Create an API key in Templafy with the scope library.generate. Make sure to copy the key and keep it handy.
  2. Find the template in Templafy that will be used to generate documents in this flow. Copy the asset ID of that template



  3. Find the Space ID of the Space in which the template is added.

 

 

Configuration of Packaged Flow in Salesforce

  1. Install and configure the Templafy App Package in Salesforce. Follow the steps in this article.

Update Named Credentials Object and Add API Key

  1. In the Salesforce Setup App, search for Named Credentials and navigate to the Named Credentials Page



  2. Click on the TemplafyApi link



  3. Click on the Edit button on the top of the page



  4. Replace [TEMPLAFYTENANTID] in the URL with your Tenant ID. Click Save
    If your URL is https://companyname.templafy.com, then your tenant id would be companyname



  5. Click on TemplafyApiKey under Authentication.



  6. In Principals section, find the TemplafyConnection parameter, click on the arrow and select Edit



  7. In the popup, in Authentication Parameters, click Add to add a new authentication parameter



  8. Fill in the following values and Save:
    • Name: ApiKey
    • Value: Your Templafy API key with the library.generate scope

 

Add the External Credential Principal to User Profiles

  1. In the Salesforce Setup App, search for Profiles and navigate to the Profiles page



  2. Locate the profile you to which you'd like to add the permission, and click on the name to open it



  3. Scroll to or click on Enabled External Credential Principal Access



  4. Click on Edit



  5. Add TemplafyApiKey to the Enabled External Credential Principals section and Save

    2024-06-27_13-58-50.gif

 

Create a Custom Button to Run the Flow

  1. In the Salesforce Setup App, go to the Object Manager
  2. Find and click on the Object this flow should run on



  3. In the Object menu, go to the Buttons, Links, and Actions page



  4. Click on New Button or Link



  5. Fill in the Following Fields:
    • Label: Desired display name of the action. 
    • Display Type: How this action will be displayed. This example uses Detail Page Button
    • URL: Enter the following URL text:
      /flow/Templafy/Create_Document?AssetId=[ASSET_ID]&SpaceId=[SPACE_ID]&RecordId={![SALESFORCE_OBJECT_NAME].Id}&AssetType=[ASSET_TYPE]&retURL=/{![SALESFORCE_OBJECT_NAME].Id}

      Replace [ASSET_ID] with the Asset ID copied from the Templafy template
      Replace [SPACE_ID] with the Space ID of the template
      Replace [SALESFORCE_OBJECT_NAME] with the API name of the Salesforce Object (e.g. Opportunity)
      Replace [ASSET_TYPE] with the type of document your selected template is (Document, or Presentation)



Set Attribute to Determine File Output Format

When generating documents using this Salesforce flow, you can determine the output format of that document by indicating a field on the Object that controls the behavior

This field needs to be a Boolean data field (true / false).

  • True: Document output will be in an editable format (i.e. .pptx or .docx)
  • False: Document output will be in a .pdf format
  1. In the Salesforce Setup App, search for Custom Metadata Types and navigate to the Custom Metadata Types page



  2. Find TemplafyDocumentFormat and click on Manage Records



  3. Click on New



  4. Type the name of object for the label, find the object in the Object Selector picklist and find the relevant field in the Field Selector picklist.
 
  • If no field is configured for this action, the default output format will be .pdf.

 

Add Button to Object Page

One option that would allow you to use this custom document creation flow is by adding a button to the object page.

  1. Navigate to the Object page corresponding to the relevant object (for example, Opportunity)
  2. Click on the gear icon at the top of the page, and click on Edit Page



  3. Click on the Highlights Panel in the layout, and then click on Upgrade to Dynamic Actions in the right menu.
  4. Click Migrate, and choose the current layout. Click Finish.
  5. Click on the Highlights Panel again, and click Add Action



  6. Search for the Custom Button you previously created. Click on that to add it.



  7. Drag the new button to the top of the list so that it's visible to users.
  8. Save the page.

 

 
  • Note: If you use the Dynamic Actions method on a Lightning page, Salesforce permanently enables Dynamic Actions on that Lightning page. When Dynamic Actions is enabled, the page ignores buttons and actions on classic page layouts, and the only way you can set buttons and actions for that Lightning page is by using Lightning App Builder.

 

 

Template Configuration

This flow from Salesforce utilizes the Document Generation public API endpoints. When the flow runs, the API call made to Templafy will include one data field that corresponds to the record ID of the origin object. It will also include the current user's email address from Salesforce, which must match an email address associated with an active Templafy account. 

An example of the API value sent to Templafy:

{
"email": "User@templafy.com",
"data": {
"RecordId": "<Current Salesforce Object ID>"
},
"includePdf": true
}

To include additional data from the Salesforce record in the generated document, the Salesforce Data Connector is needed.

With the ExternalDataSources[] function in the Templafy smart template, the "HostSystem" RecordId field can be used to pull in additional Salesforce information. 

For example:

Binding {{ExternalDataSources.Opportunity[HostSystem.RecordId].Amount}}

 

 

Related articles

 

 

sharepoint Salesforce stuf tech_role
Was this article helpful?
0 out of 0 found this helpful

Comments

0 comments

Article is closed for comments.