Christoffer Utterborn
Christoffer Utterborn
  • Updated

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.

  1. Define the Oneflow Contract name – Enter the name of the contract or select it from a flow variable.
  2. Insert your Oneflow Workspace ID – Enter the Oneflow Workspace ID or select it from a flow variable.
  3. Select one Template ID available in your Oneflow workspace – Enter or select it from a flow variable.
  4. 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.
  5. 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).
  6. 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

  1. 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.

    1. How to create an Apex-defined variable for PotentialParticipant:

      1. Resource Name → Variable
      2. API name → for example, OneflowParticipant
      3. Data Type → Apex-Defined
      4. Apex Class → Select OFapp__PotentialParticipant from the dropdown
      5. Check the “Available for input” checkbox.
    2. How to create an Apex-defined collection variable for PotentialParticipant:

      1. Follow the same steps as above but check “Allow multiple values (collection)” to create a collection variable.
  2. 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.

  3. 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
  1. Add the populated object to the Apex-defined collection variable created for PotentialParticipant.
  1. 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

  1. 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.

    1. How to create an Apex-defined variable for OneflowAttachment:

      1. Resource Name → Variable
      2. API Name → e.g., OneflowAttachment
      3. Data Type → Apex-Defined
      4. Apex Class → Select OFapp__OneflowAttachment
      5. Check the “Available for input” checkbox.
    2. How to create an Apex-defined collection variable for OneflowAttachment:

      1. Follow the same steps and check “Allow multiple values (collection)” to create a collection variable.
    3. Create a collection variable to hold the Content Document IDs (optional). Data Type → Text, and check “Allow multiple values (collection)”.
  2. 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.
    1. Fetch the ContentDocumentLinks using the LinkedEntityId (the related record ID in Salesforce).
  1. Add the retrieved ContentDocument IDs to the collection variable you created earlier.
  1. Fetch the ContentDocuments using those IDs.
  1. Loop through the retrieved ContentDocuments and assign their values to the OneflowAttachment records. Required fields include Title, Created Date, Description, File Extension, and Size.
  1. 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.

Was this article helpful?

0 out of 0 found this helpful

Have more questions? Submit a request