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
AnbuAnbu 

email to case trigger to delete a case?

Hello guys,

I have just started developing and I am following the current situation:

we're using community and we want to implement email-to-case. The only problem is that with partner licenses we cannot reply emails directly from Case object and this is mean that if we receive a case from email to case, we can only reply by email and this is also mean that we will get a new case for each reply and it will be a real mess in our salesforce.

I read that you can do some tricks by code. Any idea how to write a trigger that would do the following:

If the person will reply back to the current case, then the trigger will add the conversation to the first case and will delete the second case and so on.

I hope this is clear and someone can help with this!

Thanks a lot!

 
Khan AnasKhan Anas (Salesforce Developers) 
Hi Andrea,

Greetings to you!

According to Salesforce Knowledge Article (https://help.salesforce.com/articleView?id=000004218&type=1):

When the Thread ID is missing in emails sent from cases, the response email will come back without the thread ID too. Without the Thread ID, the Salesforce system can't determine which case the email is related to, so the system treats it as a new email and creates a new case.

To fix the issue, insert a Thread ID merge field for auto-response emails in Email-to-Case.

Create auto-response template with unique identifier

Note: These changes must be made by System Administrators
1. Create a template.
    A. Click Setup.
    B. Under 'Administration Setup,' click Communication Template | click Email Templates.

2. When selecting merge fields to include pick, 'Case Fields / Case Thread Id.' Insert the field in the subject and body of the message. To learn more, please review Generate Emails From Records (https://help.salesforce.com/articleView?id=valid_merge_fields.htm&type=0).

3. Use the newly created template for email-to-case generated cases auto-response rules. 
    A. Click Setup.
    B. Under 'Build,' click Customize | then click Cases | Case Auto-Response Rules.

Not sure it helps, but please refer to the below links which might help you further with the above requirement.

http://sforcehacks.blogspot.com/2012/01/email-to-case-can-create-too-many-cases.html

https://success.salesforce.com/answers?id=90630000000D31OAAS

I hope it helps you.

Kindly let me know if it helps you and close your query by marking it as solved so that it can help others in the future. It will help to keep this community clean.

Thanks and Regards,
Khan Anas