This guide explains how to use the Contract Create Apex Action in Salesforce Flow to automate contract creation in Oneflow; so users don’t need to trigger it manually. This enables Salesforce admins to configure logic-driven automation based on business rules.
You can find this action in the Salesforce Flow by opening the Actions menu. When you add a new Action element to the flow, the Actions menu will appear. In the search bar, search “ofapp”; this will show you all the actions related to the Oneflow app.
Input Fields
This action includes six input fields.
- Define the Oneflow Contract name – Enter the name of the contract or select it from a flow variable.
- Insert your Oneflow Workspace ID – Enter the Oneflow Workspace ID or select it from a flow variable.
- Select one Template ID available in your Oneflow workspace – Enter or select it from a flow variable.
- Select the ID of the record related to the Oneflow Contract – Enter the Record ID of the Salesforce record you want to associate the contract with. For example, to link the contract to a specific Opportunity, enter that Opportunity ID.
- Attachments Inputs – New resource list of Apex-Defined OneflowAttachment class. This is an Apex-defined collection variable that contains OneflowAttachment objects (created by querying the required Salesforce Attachment records).
- Participant Inputs – New resource list of Apex-Defined PotentialParticipant class. This is an Apex-defined collection variable that contains PotentialParticipant objects (created by querying Salesforce records).
Creating a New Resource List of the Apex-Defined PotentialParticipant Class
-
First, create the required Apex-defined variables to hold the data:
- Create an Apex-defined variable for a single PotentialParticipant.
- Create an Apex-defined collection variable to store a list of PotentialParticipants.
In Flow Builder, go to the Toolbox and click New Resource.
-
How to create an Apex-defined variable for PotentialParticipant:
- Resource Name → Variable
- API name → for example, OneflowParticipant
- Data Type → Apex-Defined
- Apex Class → Select OFapp__PotentialParticipant from the dropdown
- Check the “Available for input” checkbox.
-
How to create an Apex-defined collection variable for PotentialParticipant:
- Follow the same steps as above but check “Allow multiple values (collection)” to create a collection variable.
-
Use the Get Records flow element to query the records you want to assign as Oneflow participants. For example, query the Opportunity Contact Roles related to a specific record ID.
- Assign values to the OneflowParticipant object fields using the records you fetched from Salesforce. For multiple records, use a For Each loop to process them one by one. Refer to the official documentation: https://developer.oneflow.com/docs/participant
- Add the populated object to the Apex-defined collection variable created for PotentialParticipant.
- Pass the Apex-defined collection variable to the Participant Inputs field of the Create Contract action.
Creating a New Resource List of the Apex-Defined OneflowAttachment Class
-
Create the necessary Apex-defined variables:
- One Apex-defined variable for a single OneflowAttachment.
- One Apex-defined collection variable for multiple OneflowAttachments.
To create these variables, go to the Toolbox in Flow Builder and click New Resource.
-
How to create an Apex-defined variable for OneflowAttachment:
- Resource Name → Variable
- API Name → e.g., OneflowAttachment
- Data Type → Apex-Defined
- Apex Class → Select OFapp__OneflowAttachment
- Check the “Available for input” checkbox.
-
How to create an Apex-defined collection variable for OneflowAttachment:
- Follow the same steps and check “Allow multiple values (collection)” to create a collection variable.
- Create a collection variable to hold the Content Document IDs (optional). Data Type → Text, and check “Allow multiple values (collection)”.
- Fetch the required ContentDocument records from Salesforce to assign values to the OneflowAttachment object. In this example, fetch attachments linked to an Opportunity by first retrieving the related ContentDocumentLink records.
- Fetch the ContentDocumentLinks using the LinkedEntityId (the related record ID in Salesforce).
- Add the retrieved ContentDocument IDs to the collection variable you created earlier.
- Fetch the ContentDocuments using those IDs.
- Loop through the retrieved ContentDocuments and assign their values to the OneflowAttachment records. Required fields include Title, Created Date, Description, File Extension, and Size.
- Assign the OneflowAttachment object to the Apex-defined collection variable for OneflowAttachments.
Finally, pass the Apex-defined collection variable to the Attachments Inputs field of the Create Contract action.