• Jai Prakash kumar
  • NEWBIE
  • 0 Points
  • Member since 2021

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 2
    Replies
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();
                   em.RelatedToId=cs.Id;
                    em.Subject=cs.Subject;
                    
                  
                    em1.Add(em);
                    
                  
                    
                }
                
                
            }
            
        }
        insert em1;
      
        
    }
}

what can i do , please suggest any Solution.
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();
                   em.RelatedToId=cs.Id;
                    em.Subject=cs.Subject;
                    
                  
                    em1.Add(em);
                    
                  
                    
                }
                
                
            }
            
        }
        insert em1;
      
        
    }
}

what can i do , please suggest any Solution.