This article walks through Templafy's packaged Salesforce flow that uses Templafy's Document Generation API endpoints. The information in this article includes the necessary setup steps to use the packaged Salesforce flow to automate a specific template. It also includes some optional and suggested steps to accomplish different results.
Prerequisites
|
Configuration steps in Templafy
-
Create an API key in Templafy with the scope
library.generate
. Make sure to copy the key and keep it handy. - Find the template in Templafy that will be used to generate documents in this flow. Copy the asset ID of that template:
- Find the Space ID of the Space in which the template is added.
Configuration of Packaged Flow in Salesforce
Install and configure the Templafy App Package in Salesforce following the steps in this article.
Update Named Credentials Object and add API Key
- In the Salesforce Setup App, search for 'Named Credentials' and navigate to the Named Credentials Page:
- Click on the TemplafyApi link:
- Click on the Edit button on the top of the page.
- Replace [TEMPLAFYTENANTID] in the URL with your tenant ID and click Save.
If your URL is https://companyname.templafy.com, then your tenant ID would be 'companyname'. - Click on TemplafyApiKey under Authentication:
- In Principals section, find the TemplafyConnection parameter, click on the arrow and select Edit:
- In the popup, in Authentication Parameters, click Add to add a new authentication parameter:
- Fill in the following values from the created API Key (step 1 in Configuration steps in Templafy) and click Save:
- Name: Name of the created API Key.
-
Value: Your Templafy API key with the library.generate scope.
Add the External Credential Principal to user profiles
- In the Salesforce Setup app, search for 'Profiles' and navigate to the Profiles page:
- Locate the profile you to which you would like to add the permission, and click on the name to open it:
- Scroll to or click on Enabled External Credential Principal Access:
- Click on Edit:
- Add 'TemplafyApiKey' to the Enabled External Credential Principals section and click Save:
Create a custom button to run the flow
- In the Salesforce Setup app, go to the Object Manager.
- Find and click on the object this flow should run on:
- In the Object menu, go to the Buttons, Links, and Actions page:
- Click on New Button or Link:
- 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
, orPresentation
).
- Replace
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.
- In the Salesforce Setup app, search for 'Custom Metadata Types' and navigate to the Custom Metadata Types page:
- Find TemplafyDocumentFormat and click on Manage Records:
- Click on New:
- 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.
NoteIf 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.
- Navigate to the object page corresponding to the relevant object (for example, Opportunities).
- Click on the gear icon at the top of the page, and click on Edit Page:
- Click on the Highlights Panel in the layout, and then click on Upgrade to Dynamic Actions in the right menu.
- Click Migrate, and choose the current layout. Click Finish.
- Click on the Highlights Panel again, and click Add Action.
- Search for the Custom Button you previously created. Click on that to add it.
- Drag the new button to the top of the list so that it's visible to users.
- Save the page.
ImportantIf 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 uses 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.
Binding example: {{ExternalDataSources.Opportunity[HostSystem.RecordId].Amount}}
.
Comments
Article is closed for comments.