I have a scenario where clients sometimes copy in two different email-to-case addresses, which results in 2 cases being created when I only want one, its not an issue which address its created against.

So I tried capturing this in the Case trigger, however, the emails hit SF at the same time but create two different trigger instances, which are unaware of each other, so I can't do some action on the 2nd email because the first email/case hasn't yet been committed.

Any ideas how to deal with this?

2 Answers 2


Each Case will have a different threadId and the client will receive (if configured) two different auto-response emails. If the client wishes to add more comments to the case by replying to the auto-response, only one of the Cases will get the update. If you delete one of the two cases, you might be deleting the Case the client plans on responding to anew or the Case your service rep is already working on.

As such, even if you had an asynchronous APEX pattern (like Dan Appleman's) in place to delete one of the two Cases (the one that has no activity on it beyond inception), you might delete the Case the client thinks is the valid one.

Hence, such an asynchronous deletion pattern will need to re-inform the client of the 'true' Case - with explanation that duplicate Cases were errantly created.

Such asynchronous Apex pattern would run every minute (5 minutes) looking for stuff to do as driven by Appleman's custom Async_Request__c object (which corresponds to a new email-to-Case creation). You would look to see if there was a duplicate Case, figure out which of the two should be deleted, and notify the client with email alert of what happened.


The easiest would simply be to run a report that groups Cases by Subject. When you see two or more with the same subject delete one of them. This is manual, but I'd hope this issues of using 2 email addresses doesn't happen often.

Alternatively you could replace EmailToCase with Email2Apex and write your own Apex email parser/handler. A lot more work.

Both of the above assume you need both EmailToCase email addresses for proper Case routing, but you could also get rid of one of those email addresses and just use a single EmailToCase email address. Not sure that the business requirements support this, but it would also easily eliminate duplicates.

You must log in to answer this question.

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