Hear from Salesforce leaders on how to create and deploy Agentforce agents.
Contact Us 1-800-596-4880

Generative Flow Examples

Use these examples to help you get started with the generative flow feature and understand how to create messages for your own use cases.

Implement a New Case Notification

Your company receives numerous customer inquiries and support requests daily. You want to implement email notifications whenever a new case is created in Salesforce so you can respond quickly to customers and ensure timely case resolution to increase customer satisfaction.

To generate a flow for this task, enter a message like: Generate a flow that sends an email when a case is created in Salesforce.

This message generates XML code for the new flow, similar to this:

1 This flow starts with a Salesforce Connector on-new-object-listener trigger so that when a new case is created, the flow is triggered.
2 The payload for the new case is set in variables using a DataWeave script within the Transform component.
3 The email is sent using the Email Connector Send operation with the configured SMTP settings.

The subject of the email is set to `New Case Created: ` followed by the case subject.

4 The body of the email is set to HTML format and includes the case ID, subject, and description.

Complete the Flow

After reviewing and inserting the generated flow into your project:

  1. Type the target email address to use in your use case, for example:

    <email:to-address value="demo@gmail.com" />

  2. Add the target email, ${email.username} to your configuration properties file.

  3. Optionally, enter a value for the scheduling strategy in the fixed-frequency attribute. The Scheduler initiates the flow to poll for new cases according to the value you set, for example:

    <scheduling-strategy>
        <fixed-frequency frequency="5000" />
    </scheduling-strategy>
    xml

    This example flow is configured to poll for new cases every 5000 milliseconds.

  4. Use built-in snippets to add configurations for your Salesforce instance and email inbox.

The following is an example of the completed flow:

Update a Phone Number

Provide a streamlined process for Salesforce System Administrators by using an API call to efficiently and securely update a phone number.

To generate a flow for this task, enter a message like: Create a flow that listens for an API call and updates the phone number of a Salesforce Account object.

This message generates XML code for the new flow, similar to this:

<flow name="updatePhoneNumber" doc:id="1">
    <http:listener doc:name="Listener" doc:id="2" config-ref="HTTP_Listener_config" path="/updatePhoneNumber"/> (1)
    <ee:transform doc:name="Set Payload" doc:id="3"> (2)
        <ee:message>
            <ee:set-payload><![CDATA[%dw 2.0
output application/java
---
{
    "accountId": payload.accountId,
    "phoneNumber": payload.phoneNumber
}]]></ee:set-payload>
        </ee:message>
    </ee:transform>
    <salesforce:update doc:name="Update Account" doc:id="4" config-ref="Salesforce_Config" type="Account"> (3)
        <salesforce:records>#[payload]</salesforce:records> (4)
    </salesforce:update>
</flow>
xml
1 The flow starts with an HTTP Listener that listens for an API call on the /updatePhoneNumber path.
2 In the Transform component, the payload is set using the <ee:transform> operation to specify the account ID and phone number to update.
3 The Salesforce Connector Update operation is used to update the Account object in Salesforce.

The type attribute is set to Account to specify the object type to update.

4 The payload is passed as the records to update in Salesforce.

Complete the Flow

To run this flow, use built-in snippets to add configurations for your Salesforce instance. For more information about built-in snippets, see Working with Code Snippets.

The following is an example of the completed flow:

Synchronize Account Objects

This flow enables real-time updates between Salesforce and your database to ensure the data is always current and accurate across both Salesforce and your database. As soon as the phone field changes in Salesforce, it updates immediately in the database and vice versa.

To generate a flow for this task, enter a message like: Create a flow that syncs the phone field of account objects between a Salesforce org and a database.

This message generates XML code for the new flow, similar to this:

1 Configure the HTTP Listener operation to listen for a POST request on the /syncAccountPhone path.
2 Extract the account ID from the payload and store it in a variable named accountId.
3 Extract the phone number from the payload and store it in a variable named phone.
4 The Database Connector Select operation retrieves the account record from the database based on the account ID.
5 Use a DataWeave Transform operation to create the updated data for the Salesforce Account object.
6 Use the Salesforce Connector Update operation to update the Salesforce account.
7 The account information is also updated in the database using a Database Connector Update operation.
8 The payload is set to Phone field synced successfully to indicate a successful sync.

Complete the Flow

After reviewing and inserting the generated flow into your project:

  1. Update the name of the database table and fields to match what is configured in your MySQL database.

  2. To run this flow, use built-in snippets to add configurations for your Salesforce instance.

The following is an example of a completed flow:

Automate New Record Notification

Automate email notifications to users when a new database record is updated to minimize manual intervention, which improves efficiency and reduces the chances of errors or delays.

To generate a flow for this task, enter a message like: Generate a flow to send an email when a record is created in the database.

This generates XML code for the new flow, similar to this:

<flow name="sendEmailFlow">
    <db:listener table="record" doc:name="On Table Row" doc:id="dbListener" watermarkColumn="CREATION_DATE">
        <scheduling-strategy> (2)
            <fixed-frequency frequency="1" timeUnit="SECONDS"/>
        </scheduling-strategy>
    </db:listener> (1)
    <set-variable variableName="record" value="#[payload]" doc:name="Set Variable" doc:id="setVariable"/> (3)
    <email:send config-ref="Email_SMTP" fromAddress="sender@example.com" subject="New Record Created"> (4)
        <email:to-addresses>
            <email:to-address value="recipient@example.com"/> (5)
        </email:to-addresses>
        <email:body contentType="text/plain">
            <email:content><![CDATA[New record created with ID: #[vars.record.id]]]></email:content>
        </email:body>
    </email:send>
</flow>
xml
1 The flow starts with a Database Connector Listener component that listens for new records in the database record table.
2 The scheduling strategy is set to trigger the flow at a fixed frequency of every one second.
3 The payload of the listener is stored in a variable named record using the Set Variable operation.
4 An email is sent from the address sender@example.com using the Email Send component.
5 The email is sent to the address recipient@example.com.

Complete the Flow

After reviewing and inserting the generated flow into your project:

  1. Update the sender email address, recipient email addresses, and email body for your specific use case.

  2. Update the database table name so that it corresponds to the database table on which the flow listens for new records.

  3. Update the watermarkColumn in the Database Listener to whichever database column is used to indicate new records.

    The values that are taken from this column are used to filter the contents of the next poll, so that only rows with a greater watermark value are processed.

  4. To run this flow, use built-in snippets to add configurations for your database and email inbox.

The following is an example of the completed flow: