- 13 Nov 2024
- 3 Minutes to read
- Print
- DarkLight
Example 5: Save Relay Power-up PDF to Salesforce
- Updated on 13 Nov 2024
- 3 Minutes to read
- Print
- DarkLight
This example should be used as a reference to understand basic concepts and ideas on integrating with Relay Network. It should not be taken literally as this is how integration to Relay must be done. You should replace your record types, field names, business logic, etc. with those that match your business process and setup.
Example Goals
Whenever a user fills out a Relay power-up form in the Feed, retrieve the PDF version of the submitted form and store it in Salesforce.
Assumptions
The user’s data is stored in a person account
The person account has a customer field called RelayCCID__c that uniquely identifies the user.
A Relay power-up form has been created and sent to a user
Security and Permissions
Record triggered flows always run as the System Context without Sharing. This provides access to all of the objects and their fields.
However, the system context does not have automatic access to making callouts to external systems. In order for this example to work, it will be making a callout back to Relay to pull (retrieve) the PDF document. Therefore, ensure that the Relay Connected App user has permissions to the Relay callout named credentials.
Flow Resources
This example does not require any flow resources to be created.
Flow Logic
(1) Create a Record-Triggered Flow
Specify the RelayPowerups__c record type
Set Configure Trigger as A record is created
Set the Entry Conditions to meet your specific business requirements. In this example, we will be looking for a specific form submission.
Set Condition Requirements to All Conditions Are Met (AND)
Add a condition: Field = Name; Operator = Equals; Value = “Powerups PDF Data Received”. Enter the value without the quotes.
Optionally, add a condition to only save PDGFs for specific forms
Add a condition: Field = FormID__c; Operator = Equals; Value = {Your specific form id}
(2) Add a Scheduled Path to the Flow
When the Relay platform generates the PDF it emits the "Powerups PDF Data Received” event. However, the PDF may still be going through a anti-virus scanner so it is possible that the file is still not available for retrieval. Therefore, we will add a scheduled path to add a slight delay, to allow for the anti-virus scanner to complete, prior to trying to retrieve the PDF.
On the Flow Start element, add a Scheduled Path
Set the Path Label to Delay
Set the API name to Delay
Set the Time Source to “When RelayPowerups_c is Created”
Set the Offset Number to 5
Set the Offset Options to Minutes After
(3) Locate the Person Account record
NOTE
This example assume the Person Account object has a custom RelayCCID__c field. If the value for the Relay CCID is the ID of your Salesforce record then no additional lookup will be required as you can use the value provided with the form submission.
Set the Object to Account
Set the Condition Requirements to All Conditions Are Met (AND)
Set the Field to RelayCCID__C; set the Operator to Equals; set the Value to {!$Record.RelayCCID__c}
Set the How Many Records to Store option to Only the first record.
Set the How to Store Record Data option to Automatically store all fields.
(4) Make sure we located the Person Account
If the record was not located you should add the proper notifications to your business team to inform them of the error. This logic has not been included in this example.
(5) Add a RelayPullPDFAction to the Flow
This Relay action will pull the PDF into your Salesforce org. For this example, the action will automatically store the PDF as a File associated with the record of the ID located in step (2).
See the Relay Pull PDF Action article for details on all of the Action input values.
(6) Add Decision Element
IMPORTANT
In a production system, you should check the result of the RelayPullPDF element, and take appropriate action based on your business requirements.
Refer to the Relay Pull PDF Action article for details on the returned result object and its values.
In this example, we show the three possible outcomes when attempting to retrieve the PDF from Relay.
Delayed: This branch is taken when Relay reported that the PDF file was not ready yet.
OK: The PDF was pulled and stored in Salesforce
Error: There was an error pulling the PDF from Relay. Review the returned statusMessage value for the specific reason.