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
Jai Prakash kumarJai Prakash kumar 

How can i prevent to create Duplicate case record in Email-to-case

Hi All,
I am new to Salesforce .
I have configured Email-to-Case in my org.its working fine but
when i used to send a mail to my configured mail-id a case  record is getting created. 

when i am sending second mail i didn't want to create case record with my second mail.

Simply i want to attached the mail to my previous record.

I have written below code:
trigger UpdateCaseTrigger on Case (before insert) {
    if( Trigger.isBefore){
        List<Case> cs1=[select id,Status,SuppliedEmail,Subject,Description,Origin from Case];
        List<EmailMessage> em1=new List<EmailMessage>();
        for(case cs:Trigger.New){
            for(case cs2:cs1){
                if(cs.SuppliedEmail==cs2.SuppliedEmail && cs2.Status=='New'){
                   EmailMessage em=new EmailMessage();
        insert em1;

what can i do , please suggest any Solution.
SwethaSwetha (Salesforce Developers) 
HI Jai,
Are you sending your emails to the "email service address"?


Jai Prakash kumarJai Prakash kumar
Hi Swetha,
Yes, I am sending emails to "Email Service Addess".
Maharajan CMaharajan C
Hi Jai,

Do you have thread id's in email's. If thread id is there then Salesforce automatically map the emails under original case. If you don't want to use the thread id concept then write the custom code to delete the duplidate case and the append the email message under existing one.

Please go throw the slide in the below to learn complete salesforce email to case.

Robert A. EliasRobert A. Elias
I'm having an issue where we're getting multiple cases opened via one email thread. I know what the issue is, but I'm wondering if there are any best practices or something that can be put in place that help avoid this issue. Here is what happened: 
1. Customer emailed Sales Tech directly. They go back and forth on email.
2. At some point our support email address is added to the cc field.FaceTime (
3. Everytime they reply all a new case is added.
I know this is because the thread ID is missing. Technically Sales Tech should wait for the email that a new case is received (which includes the Thread ID) and reply all to that (since it includes the contact)... then if they go back and forth on that it will track to one case.
Is there anything else that can be done/put in place in these cases? We don't have them often - but when they occur they are a pain. 
Jai Prakash kumarJai Prakash kumar
Hi Maharajan,
can you suggest me or give me some hint how can i write Custom code, if you have any example.