How to create a Salesforce flow that returns last email sent date on the case ?

How to create a Salesforce flow that returns last email sent date on the case ?

On April 1, 2024, Posted by , In Salesforce, With Comments Off on How to create a Salesforce flow that returns last email sent date on the case ?

Creating a Salesforce Flow to return the last email sent date on a case involves querying the EmailMessage object, filtering the results based on the CaseId, and then sorting the records to find the most recent date. Here’s how you can do it step by step:

1. Create a New Flow

  1. Navigate to Setup.
  2. In the Quick Find box, type “Flows”.
  3. Select Flows, then click on the ‘New Flow’ button.
  4. Choose ‘Record-Triggered Flow’ for this purpose.

2. Configure the Flow Trigger

  1. Set the object to ‘Case’.
  2. Choose the trigger point (for this scenario, it might be when a record is created or updated).
  3. Set the condition requirements that must be met for the flow to run.

3. Get Records Element to Query EmailMessage Object

  1. Drag and drop a ‘Get Records’ element onto the canvas.
  2. Label it appropriately (e.g., ‘Get Last Email Sent’).
  3. Set the object to ‘EmailMessage’.
  4. Set filter conditions to only get emails related to the CaseId. For instance, where ParentId Equals {!$Record.Id} (assuming you’re triggering from a Case record).
  5. Order the records by ‘MessageDate’, descending.
  6. Choose to store only the first record (which will be the most recent due to the sorting).

4. Set a Variable to Hold the Last Email Sent Date

  1. If you don’t already have a variable for the last email sent date, create one.
  2. Use an Assignment element to set this variable to the MessageDate of the record retrieved in the previous step.

5. Update the Case Record

  1. Drag and drop an ‘Update Records’ element onto the canvas.
  2. Configure it to update the Case record that triggered the flow.
  3. Set the field where you want to store the last email sent date to the variable holding that date.

6. Save, Activate, and Test the Flow

  1. Save the flow and give it an appropriate name and description.
  2. Click ‘Activate’ to make the flow live.
  3. Test the flow by updating or creating a Case (based on your trigger conditions) and then checking to see if the Last Email Sent Date is updated correctly.

Make sure to add appropriate fault handling and consider bulkification (how the flow will behave with bulk operations) to ensure the flow is robust and efficient. Also, it’s good practice to add comments or descriptions within your flow for documentation and clarity.

Comments are closed.