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
Ceejay djoCeejay djo 

Email to Case - Modify Inbound Email before conversion to Cases

I have an issue where some clients send sensitive data through inbound emails. I am trying to avoid that and I am looking out for a possible solution. Is there a functionality available in Salesforce where you have the chance to modify the body of this inbound email and delete out these sensitive data before it converts to case? Is this even possible to be done? Any comments or help is appreciated? 
Best Answer chosen by Ceejay djo
Veenesh VikramVeenesh Vikram
Hi,

In case to achieve the same. You will have to write your own custom "Inbound Email Handler".
Refer: https://developer.salesforce.com/page/An_Introduction_To_Email_Services_on_Force.com
Example: http://blog.jeffdouglas.com/2010/03/12/writing-an-inbound-email-service-for-salesforce-com/

Using this, you can get rid of the sensitive data using your logic and then create Cases from the different elements of email.

Kindly mark solved if this resolves your issue.

Best Regards
Veenesh

All Answers

Veenesh VikramVeenesh Vikram
Hi,

In case to achieve the same. You will have to write your own custom "Inbound Email Handler".
Refer: https://developer.salesforce.com/page/An_Introduction_To_Email_Services_on_Force.com
Example: http://blog.jeffdouglas.com/2010/03/12/writing-an-inbound-email-service-for-salesforce-com/

Using this, you can get rid of the sensitive data using your logic and then create Cases from the different elements of email.

Kindly mark solved if this resolves your issue.

Best Regards
Veenesh
This was selected as the best answer
Ceejay djoCeejay djo
Thank you!
Anand kurubaAnand kuruba
Hi,

global class Caseinboundmassage implements Messaging.InboundEmailHandler{
    
    global Messaging.InboundEmailResult handleInboundEmail(Messaging.InboundEmail email,Messaging.InboundEnvelope env){
        Messaging.InboundEmailResult result = new Messaging.InboundEmailResult();
        
        //how we can get from address 
        String conemail = email.fromAddress;
        system.debug('conemail====='+conemail);
        
        
        //check contact have this email
        contact con = [SELECT id,Name FROM Contact WHERE email =: conemail limit 1];
        system.debug('Contact is'+con);
        
        if(con != null){
            //creat case
            Case cas = new Case();
            cas.contactid = con.id;
            cas.Subject = email.subject; 
            cas.Origin = 'Email';
            cas.Status = 'New';
            cas.Priority = 'low';
            cas.Description = email.plainTextBody;
            
            try{
                insert cas;
                result.success = true;
            }Catch(DMLException e){
                system.debug('Following error message occured==== '+e);
                result.success = False;
            }
              if(email.textAttachments != null)
        {
            // Save attachments, if any
            for (Messaging.Inboundemail.TextAttachment tAttachment : email.textAttachments) {
              Attachment attachment = new Attachment();
             
              attachment.Name = tAttachment.fileName;
              attachment.Body = Blob.valueOf(tAttachment.body);
              attachment.ParentId = cas.Id;
              insert attachment;
            }
        }
        if(email.binaryAttachments != null)
        {
            for (Messaging.Inboundemail.BinaryAttachment bAttachment : email.binaryAttachments) {
              Attachment attachment = new Attachment();
             
              attachment.Name = bAttachment.fileName;
              attachment.Body = bAttachment.body;
              attachment.ParentId = cas.Id;
              insert attachment;
            }
        }
            

        }else{
            system.debug('Contact Not Exist');
        }
        
        return result;
    }

}

please choose best answer!!

thanks!!