function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Matt BostromMatt Bostrom 

Email-To-Case Filtering

Hi all,
I'm looking for an efficient way at filtering out some of the emails that come in to our Email Service Address so that it will not auto-create a case in SFDC if its from a particular email.

I am aware there is an Email to Case premium module but am not interested in paying for more that.

I've tried varous things like putting addError on the before insert of the EmailMessage (however this throws email exceptions and also won't work in bulk as it rolls back all DMLs and not just the ones with the errors).

I've also tried triggers on Case and EmailMessages to perform some checks and updates/deletes. That was working but has some problems on its own so I'd rather not continue down that path.
pconpcon
What we do is to push it to a Span queue and strip of the Contact and Account information.  If we really do not want it to be committed then we do the addError.  You do't need to worry about the buik since EmailMessage (at least in the real world use) are only insert as singletons and never as bulk.

I would put your trigger on the Case for a before trigger.  Then fetch down all the EmailMessages for the cases (probably filtering on the Email origin) and then if the EmailMessage from address equals the one you don't want then change the OwnerId to your spam queue and set ContactId and AccountId to null.  Then if you want to clean up that data you can write a scheduled job that will come along and delete them after the fact.  Or you can leave them hanging around for X number of days/weeks/years for forensic work.
Matt BostromMatt Bostrom
we found though that with the .addError its actually generating an email to the DEV team regarding the validation exception from the .addError. Any way to suppress the fault message to an email box JUST for this block of code? we have tried TRY/CATCH but to no avail...
pconpcon
No, addError will always send that message.  We have all our error messages go to a mailing list and then we filter our the ones that have our addError message before it gets delivered.