I need to automate the process of creating a new case for each new mail received in an email id and salesforce already has a feature called 'email-to-case' feature for setting up this automation. I tried it and it worked fine. But the email-to-case settings doesn't have a feature to set the contact and account fields.

What I had in mind is of an apex trigger which runs after a case is created by the email-to-case automation. The trigger runs a SOQL query to get the contact record with email that matches the sender's email id and updates the contact field (also updates the account field by the contact's account) of the case.

But my issue is if I place the trigger in Case object, the trigger will run even for the cases that were created manually which is not what I want. I only want the trigger to work if the cases are created from the email-to-case feature. I had an idea to only run the query and corresponding update if the case record had the field 'SuppliedEmail' i.e. web email filled and contact field empty. Does that make sense? or am I doing this wrong?

1 Answer 1


Why don't you just make two record types? Use one for Email-to-Case, it can be set up in the routing address settings.

You'll get the Record type ID and you can try using it in a trigger afterwards.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .