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:
- Configuration Steps in Templafy
- Configuration of Packaged Flow in Salesforce
- Update Named Credentials Object and Add API Key
- Add the External Credential Principal to User Profiles
- Create a Custom Button to Run the Flow
- Set Attribute to Determine File Output Format
- Add Button to Object Page
- Template Configuration
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. Follow 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. Click
Save
If your URL is https://companyname.templafy.com, then your tenant id would becompanyname
- 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 and Save:
- Name: ApiKey
- 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'd 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 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
)
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.
|
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, Opportunity)
- 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.
|
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
Comments
Article is closed for comments.