Contact Us 1-800-596-4880

Invoking a Composer Flow

Invoke a Composer flow from external systems to enable deeper interoperability and integrated capabilities across Salesforce. You can also authenticate every invocable flow for a secure and protected automation experience, create API-compatible invocable actions for seamless integration with diverse systems and applications, and build powerful automations by leveraging the built-in support for input and output fields.

When your invocable flow is activated, Composer exposes a unique flow URL and a unique pair of client credentials (client ID and client secret) so that your flow can be invoked from external systems. You can reset these credentials for security best practices. Invoke invocable flows by using an HTTP call to the flow URL and using the flow client credentials as authentication.

To invoke a Composer flow:

Create an Invocable Composer Flow

Create an invocable Composer flow so that you can invoke it later from an external system:

Configure Your Invocable Composer Flow

To configure an invocable Composer flow:

  1. Access Composer.

  2. Create a new flow from scratch.

  3. In the What Should Start This Flow? dialog, in the Interaction section, click Invoke to create an invocable flow.

    The Trigger: Invoke this flow from an external system via HTTP POST Request trigger appears.

  4. Optionally, add input fields. For example, you can add an Opportunity ID input field that returns a value if Salesforce passes the value of an opportunity ID to the Composer flow.

    To add input fields, click Add Input Fields. You can define input fields by using the Visual Editor or Sample JSON Editor.

    • To define input fields using the Visual Editor:

      1. In the Input Name field, enter a unique name for the input field. The name must begin with a letter and cannot contain spaces.

      2. In the Data Type dropdown, select the data type you want to use for the input field. The following data types are supported: String, Number, Boolean, Date, and DateTime.

      3. Optionally, add a value for Sample Value or Help Text to test the flow.

      4. To add more input fields, click Add Input.

      5. Click Apply.

        The count of input fields you added appears next to Input Fields, displaying one or more new input fields added to the flow.

      6. Optionally, to change the input fields, click Add Input Fields to open the Visual Editor.

    • To define input fields by using the Sample JSON Editor:

      1. In the Example Request window, paste or enter the JSON sample.

        Example: JSON sample in the Sample JSON Editor window
        {
        {
        "name": "ben",
        "age": 100
        }
        }

        Unlike the Visual Editor, the Sample JSON Editor supports objects, arrays, and null values.

        Example: Complex JSON sample in the Sample JSON Editor window
        {
        "data": {
        "favoriteNumbers": [3, 7, 13, 17, 23]
        }
        }
      2. Click Apply.

        The count of the of input fields you added appears next to Input Fields, displaying one or more new input fields added to the flow.

      3. Optionally, to change the input fields, click Add Input Fields to open the Sample JSON Editor to edit the input fields.

  5. Optionally, add output fields. If specified, output fields are returned as the JSON response. For example, if there is an Opportunity ID input field, you can add the value of the ID as an output field, in which the following JSON response is returned with a 200 status code:

    {
    "opportunityId": "<id>"
    }

    To add output fields:

    1. Click Add Output Fields.

    2. In the Label field, enter a unique name for the output field. The name must begin with a letter. Avoid including spaces in this field since spaces are escaped and replaced with x20.

    3. In the Data Type dropdown, select the data type you want to use for the output field. The following data types are supported: String, Number, Boolean, Date, and DateTime. If you select List, in the List Item Type field, select:

      • String, Number, or Boolean to return a list that contains primitive data types

      • Object to return a list of objects, for example, the output of the Get Records action

    4. Click Apply.

    5. Once output fields are added, you can then map data pills, custom expressions, or plain text. For example, map an input field to the output field.

      • String, Number, Boolean, Date, or DateTime, a value is required. You can enter a value manually, select any existing data pill (including variables) from your flow, select a Picklist Mapping (for String variables) or you can select the Custom Expression Editor to create a custom expression.

      • List, a value is required. You can enter a value manually. For primitive list types (String, Number, Boolean, Date, or DateTime), you can create a list statically using the Custom Expression Editor or map in a list data pill. For List<Objects>, select either:

        • Dynamic List to create multiple items in the list. Use a list pill to reference the number of items created. Then, map the fields of the elements of the list.

        • Static List, and then initialize the list with as many items as you need. If you do not add any items, the list is empty by default.

    6. Optionally to change the output fields, click Add Output Fields to open the editor to edit the output fields.

  6. Complete the flow.

    For example, configure system actions for the flow, define variables, or create flow controls as described in Configuring and Managing Flows.

  7. Click Save.

To delete an invocable step from your flow:

  1. Access the flow that contains the invocable flow step to delete.

  2. In the corner of the step, click > Delete step.

Test Your Invocable Composer Flow

To test your invocable Composer flow:

  1. In your invocable flow, click Test.

    If you added input fields, the Test Flow window appears.

  2. Enter a sample value for the input field or review the complex JSON to test the flow.

  3. Click Test Flow.

    The testing output appears. Using this output, you can verify if the flow returns the expected values in the sample output of the main canvas.

Activate Your Invocable Composer Flow

To activate your invocable Composer flow:

  1. In your invocable flow, click Activate.

    The flow details page appears with a message indicating that the flow is now active. When an invocable flow is activated for the first time, the org admin receives an email.

  2. Click Flow Credentials to view the flow data that invokes the flow from the external system. If your flow is deactivated for more than 30 days, the flow credentials will expire. New flow credentials are generated the next time your flow is activated.

  3. You can reset the flow credentials periodically to ensure continuous security.

    In the Flow Credentials window, click Reset Client Secret.

    The Client Secret field is updated.

    Click the clipboard icon next to the field to copy the new Client Secret value.

    Once the client secret is reset, the previous client secret no longer works. You must manually share the new client secret to external systems that invoke this Composer flow.

  4. Ensure the following fields have values:

    • URL: Unique URL of the flow you are invoking.

    • Client ID: Username or unique identifier to authenticate this flow.

    • Client Secret: Password or secret to authenticate this flow.

    • OpenAPI Specification: OpenAPI specification that describes the structure of the underlying API of this flow.

  5. Click Close.

Invoke the Composer Flow from an External System

After creating an invocable flow in Composer, you can invoke it from an external system:

Invoke a Composer Flow from Flow Builder

Invoke a Composer flow directly from Flow Builder to build integrations without writing a single line of code.

For example, use invocable flows to build integrations in Flow Builder that connect to third-party systems such as NetSuite, Jira, and Workday. Some use cases include using Flow Builder to call an invocable Composer flow that:

  • Creates a Jira issue when a record is created in Salesforce.

  • Retrieves an order status from NetSuite and posts a message in Slack.

  • Gets real-time credit scores when a user goes through a screen flow.

  • Retrieves an order status from NetSuite when a user enters an order ID in the screen flow.

To invoke a Composer flow from Flow Builder:

Set Up Salesforce for Invocable Flows

After creating your Composer flow, set up your Salesforce org to invoke flows in Composer:

  1. Access your Salesforce org.

  2. Create a new set of credentials that use the same credentials that you use for Composer.

    Create an external credential and a named credential. If your invocable Composer flow does not contain input fields, add a new Content-Length custom header that has a value of 0 in the external credential and named credential to avoid an HTTP 411 response.

    To create an external credential and a named credential:

  3. Register your external service by copying the API specification from the Composer flow as described in Paste the JSON-formatted Schema Into Your Browser.

Set Up Flow Builder for Invocable Flows

After setting up Salesforce for invocable flows, you can call the Composer flow from Flow Builder:

  1. Access your Salesforce org.

  2. Go to Setup > Process Automation > Flows.

  3. Click New Flow to create a new flow in Flow Builder.

  4. Select the type of flow you want to create, for example, a Record-Triggered Flow, and then click Create.

  5. Configure the start of the flow.

    If you create a record-triggered flow, select Run Asynchronously to avoid errors.

  6. Set up an invocable action.

    Click + to add a new element and then click Action.

  7. In Filter By, select Type and click External Service.

  8. Select the action of the invocable flow from the external service.

  9. Enter a value for the Label and API Name fields.

  10. If you are invoking a Composer flow with inputs, follow these steps:

    In Set Input Values, for body, set the input value to the external service that triggers the Composer flow.

    To set the input value, click New Resource and ensure the following fields have values:

    • Resource Type: Select a resource type.

    • API Name: Enter a name for the API.

    • Data Type: Select a data type.

    • Apex Class: Search for an Apex class.

    • Availability Outside the Flow: Select Available for input and Available for output if needed.

    For example, if Salesforce passes the value of an opportunity ID to the Composer flow, the values are:

    • Resource Type: Variable

    • API Name: InvocableFlowInputPayload

    • Data Type: Apex-Defined

    • Apex Class: ExternalService__InvocableFlowTest_invoke_IN_body

    • Availability Outside the Flow: Available for input and Available for output

  11. Click Done.

    The invocable action is set up.

  12. Click Done.

  13. Add an assignment by clicking + above the action to add a new element and then click Assignment.

  14. Enter a Label and API Name.

  15. Set variable values:

    • Variable: Enter the API Name of the new resource from step 10.

    • Operator: Select the operator to indicate or change the value.

    • Value: The value is assigned to the input fields when creating the invocable flow.

    For example, to set a value from a Salesforce record to an opportunity ID variable, the values are:

    • Variable: {!InvocableFlowInputPayload.opportunityId}

    • Operator: equals

    • Value: {!$Record.id}

  16. If you are invoking a Composer flow with outputs, you can use the invocable flow output in your Salesforce flow.

    For example, if your invocable flow returns an opportunity ID, you can use the Update Records flow element to assign this opportunity ID to any record field. In the Set Field Values for the Account Record section, in the Value field dropdown, your invocable flow output is available by selecting the Outputs from ActionName > 200 > [Available Output Values] option, in which ActionName is the Label or API Name from step 9 and Available Output Values is the outputs from the flow, as interpreted from the API specification added in the external service. Then, in the Field field, you can select any field on the record that you want to update.

  17. Save the flow. Enter a Flow Label and Flow API Name.

  18. Click Save.

  19. Debug the flow as described in Debug a Flow in Flow Builder.

  20. Test the flow as described in Test a Flow.

  21. Activate the flow as described in Activate or Deactivate a Flow.

Invoke a Composer Flow from Flow Orchestration

Use Flow Orchestration to create complex multi-step processes. Invoke a Composer flow in Flow Orchestration to enhance workflow automation and increase scalability.

To invoke a Composer flow from Flow Orchestration:

Set Up Salesforce for Invocable Flows

After creating your Composer flow, set up your Salesforce org to invoke flows in Composer:

  1. Access your Salesforce org.

  2. Create a new set of credentials that use the same credentials that you use for Composer.

    Create an external credential and a named credential. If your invocable Composer flow does not contain input fields, add a new Content-Length custom header that has a value of 0 in the external credential and named credential to avoid an HTTP 411 response.

    To create an external credential and a named credential:

    Note that you must add the Automated Process user to the Permission Sets assignments. For more information, refer to Assign a Permission Set to Multiple Users.

  3. Register your external service by copying the API specification from the Composer flow as described in Paste the JSON-formatted Schema Into Your Browser.

Set Up Flow Orchestration for Invocable Flows

After setting up Salesforce for invocable flows, you can call the Composer flow from Flow Orchestration:

  1. First, set up Flow Builder for invocable flows before setting up Flow Orchestration.

  2. Click New Flow > All + Templates > Flow Orchestration. Select either Autolaunched Orchestration (No Trigger) or Record-Triggered Orchestration and click Create.

    1. If you select Record-Triggered Orchestration, select the object, configure the trigger, and set entry conditions. Click Save.

  3. Click + to add a new element and then click Stage.

  4. Enter a value for the Label and API Name fields and select a condition.

  5. Click Add Step and click Background Step.

  6. Enter a value for the Label and API Name fields and select a condition and an action.

  7. Select the Contains external callouts or pause elements checkbox.

  8. Click Save.

  9. Click Activate.

Invoke a Composer Flow from Another Composer Flow

You can create an invocable flow in Composer and invoke it from another Composer flow.

To invoke a Composer flow from another Composer flow:

  1. Create a new flow from scratch.

  2. Click + > System Event and select HTTP.

  3. Configure your HTTP connection.

    For more information, refer to HTTP Connector Connections.

    Ensure that the following fields have these values:

    • Authorization Type: Basic Authentication

    • Base URL: URL of the invocable flow

    • Username: Client ID of the invocable flow

    • Password: Client secret of the invocable flow

  4. Click Next.

  5. Configure the fields to test your HTTP connection.

    For more information, refer to Test the Connection.

    Ensure that the following fields have these values:

    • Request Method: POST

    • Request Path: /

    • Request Headers

      • Key: Content-Type

      • Value: application/json

    • Request Body: Input fields of the invocable flow

  6. Click Connect.

    After the connection is created, a flow can invoke another invocable flow.

Invoke a Composer Flow from an Apex Callout

Invoke a Composer flow from Apex classes using an Apex callout. Calling a Composer flow from Apex enables more flexibility because you can call the Composer flow from a Salesforce trigger, an Apex job, an Apex controller, or a Lightning Web Component (via an Apex controller). Calling a Composer flow from a Salesforce trigger or an Apex controller is immediate, whereas calling a Composer flow as part of a flow or from an Apex job is asynchronous.

To invoke a Composer flow from an Apex callout:

Set Up Salesforce for Invocable Flows

After creating your Composer flow, set up your Salesforce org to invoke flows in Composer:

  1. Access your Salesforce org.

  2. Create a new set of credentials that use the same credentials that you use for Composer.

    Create an external credential and a named credential. If your invocable Composer flow does not contain input fields, add a new Content-Length custom header that has a value of 0 in the external credential and named credential to avoid an HTTP 411 response.

    To create an external credential and a named credential:

  3. Register your external service by copying the API specification from the Composer flow as described in Paste the JSON-formatted Schema Into Your Browser.

Use Apex Classes to Trigger Invocable Flows

After setting up Salesforce for invocable flows, you can call the Composer flow from Apex classes using an Apex callout:

  1. Access your Salesforce org.

  2. Go to Setup > Custom Code > Apex Classes.

  3. When an external service is created using the API specification from the Composer flow, Salesforce creates some Apex classes automatically. For example, suppose there is an invocable Composer flow that creates a Google Calendar meeting every time an opportunity in Salesforce is updated. The following example is an Apex class that represents the calendar meeting request body:

    // [SERVICE] GcalComposer
    // [OBJECT] GcalComposer.invoke.IN.body
    global class GcalComposer_invoke_IN_body {
        // [PROPERTY] summary
        @AuraEnabled
        global String summary {get; set{ this.summary = value; this.summary_set = true; }}
        global Boolean summary_set {get; set;}
        // [PROPERTY] description
        @AuraEnabled
        global String description {get; set{ this.description = value; this.description_set = true; }}
        global Boolean description_set {get; set;}
    }

    You can view all of the Apex classes created automatically by Salesforce under the Apex Classes section.

    The only additional step is to write Apex code to use the external service Apex classes created automatically by Salesforce. Continuing with the previous example, the following code calls out to the invocable flow to create the Google Calendar meeting:

    public class ComposerGcalFlow {
        @future(callout=true)
        public static void invokeComposerFlow(String summary, String description) {
            ExternalService.GcalComposer_invoke_IN_body body = new ExternalService.GcalComposer_invoke_IN_body();
     		body.summary = summary;
     		body.description = description;
            ExternalService.GcalComposer.invoke_Request request = new ExternalService.GcalComposer.invoke_Request();
            request.body = body;
            ExternalService.GcalComposer service = new ExternalService.GcalComposer();
            ExternalService.GcalComposer.invoke_Response response = service.invoke(request);
        }
    }

    The callout to the invocable flow code can be made from a Salesforce trigger. In the following example, the invocable Composer flow is called every time an opportunity is updated:

    trigger OpportunityUpdate on Opportunity (after update) {
    	for (Opportunity opp: Trigger.New){
    		ComposerGcalFlow.invokeComposerFlow(‘Opportunity ‘ + opp.Name + ‘updated’,opp.description);
        }
    }

    For more information about Apex callout limits and limitations, refer to Callout Limits and Limitations. For more information about Apex, refer to Apex Developer Guide.

Invoke a Composer Flow from a cURL Command

You can invoke a Composer flow through a cURL command. Because each invocable Composer flow generates a public URL, you can use the URL to invoke the flow from your terminal.

Invoking a Composer flow from a cURL command is beneficial because cURL commands can be used in scripts or code to automate business cases. cURL commands are also generally easy to share, modify, and test.

For example, suppose there is a flow that calculates some basic math and also returns a string. The flow takes three input values (a, b, and Message) and returns five output values (Output caption, Quotient, Product, Difference, and Sum). The following cURL command invokes the Composer flow, in which <url> is the flow URL and <token> is the Base64 encoding of the client ID concatenated with a colon followed by the client secret:

curl "<url>" -H "Authorization: Basic <token>" -X POST --data '
{ "a": 100, "b": 30, "Message": "Basic Math Ops" }
' -H "Content-Type: application/json"

The example response is:

{
  "Output caption": "Basic Math Ops",
  "Quotient": 3.333333333333333333333333333333333,
  "Product": 3000,
  "Difference": 70,
  "Sum": 130
}

Publish the Flow to Salesforce or an Anypoint Organization

After activating your flow, you can publish the flow to your Salesforce organization. You must have the Automation Starter or Automation Advanced subscription package to use this service.

Publish a Composer Flow from MuleSoft Composer (Beta)

To publish a MuleSoft Composer flow to your Salesforce organization:

  1. Ensure that your MuleSoft Anypoint Platform organization is connected to your Salesforce organization:

  2. Activate the flow.

  3. After activation, click the Flow Controls button that appears.

  4. In the Flow Credentials window, click Publish in the Salesforce Invocable Actions section.

    A message indicates the flow is activated and published to the selected Salesforce organization. When the flow is published to your organization, the process:

    • Generates a URL for the flow.

    • Enables External services.

    • Creates an empty permission set.

View a Published MuleSoft Composer Flow in Salesforce (Beta)

After publishing your flow from MuleSoft Composer, view your flow in Salesforce:

  1. Log in to your Salesforce organization.

  2. In the header, click The icon for Setup > Setup.

  3. In the navigation pane, navigate to or search for Mulesoft > Services.

  4. Reopen the flow in MuleSoft Composer and, in the Credentials window, note the value in the URL field.

  5. In the Imported Mulesoft Services section, in the MuleSoft Service Name column, locate and click the link that matches the value in the URL field from the previous step.

  6. In the Service section, click the link in the Named Credentials field.

  7. Click the link in the External Credential field.

    The flow information appears.

  8. You can now map users to the permission set for the flow.

Troubleshooting

When an external system successfully invokes a Composer flow, an HTTP 200 response occurs. To troubleshoot invocable flows, become familiar with the information about interpreting commonly thrown exception messages.

Missing Required Input Parameters

If a Composer flow requires input fields and the external system does not pass these fields, an HTTP 400 response occurs.

Invalid Credentials

If a Composer flow has invalid credentials, an HTTP 401 response occurs.