Problem

A customer support team needs to track when they are waiting for a customer’s reply. When an agent sends an outbound email from Salesforce, the related Case status should automatically updated to “Awaiting Customer Response”.

If the customer sends an email back, the related Case status should automatically updated to “In Progress” if the current case status is “Awaiting Customer Response”.

This automation helps agents focus on cases that require quick responses and maintain visibility into those awaiting replies, enhancing follow-ups and case resolution.

Instructions

  • Complete the given trigger handler on the EmailMessage object, which fires after an outbound email is sent.
  • Use the ParentId field on EmailMessage object to identify the related case record.
  • If the email is outbound (checked using the Incoming field), update the related Case’s status to "Awaiting Customer Response".
  • If the email is inbound, update the related Case’s status to "In Progress" only if the current case status is "Awaiting Customer Response".

Sample Data

EmailMessage Fields Sample Value
ParentId 5005g00001XyzAB

Case number : 500123
Incoming true

Result: Case #500123 status will be set to "Awaiting Customer Response"

Note

  1. The email message trigger has been deployed to your salesforce instance, and the provided afterInsert method will be invoked for the "after insert" event.
  2. Use trigger context variables (i.e., trigger.new) to access the records from the trigger handler.

Hint

Use Trigger.new to access the newly inserted EmailMessage records. Remember to check if Incoming is true before updating the Case status.

Need more practice examples?

Click here to view all apex trigger practice examples.