Email to Case - On Demand

Apex Mar 27, 2015

For Difference between Email to Case & Email to Case - on Demand click here

Setting Up Steps,

  1. Set the Default Case Owner and Automated Case Owner for your organization.
  2. Enable and configure Email-to-Case.
  3. Enable and configure On-Demand Email-to-Case.
  4. Configure your routing address settings to customize the way Salesforce handles your customer emails.
  5. Test your email routing addresses by manually sending emails to them and verify that these emails convert to cases based on their routing address settings.
  6. Add the email address that you configured to your company's support website. This is the email address customers can use to submit cases to your support team.
  7. Add the Emails related list to the Cases page layout.
  8. Optionally, create templates agents can use when replying to email. These templates can include merge fields that display information from the original email in the reply

Following Apex Class Handles email and Creates a case in Salesforce

global class CaseEmailHandler implements Messaging.InboundEmailHandler {
    global Messaging.InboundEmailResult handleInboundEmail(Messaging.InboundEmail email, Messaging.InboundEnvelope envelope) {
        //create result for email operation
        Messaging.InboundEmailResult result = new Messaging.InboundEmailresult();

        //Creating case shell
        Case c = new Case();
        c.ContactId = <<Contact_Id>>; // populating case fields hardcode/you can query contact Id here
        c.Status = 'New';
        c.Subject = email.subject;
        c.Description = email.plainTextBody;
        c.RecordTypeId = '012300000005aUz'; // pass case recordTypeId        
        insert c; // Inserting Case
        
        //Setting Result which would be helpful for debugging purposes
        
        result.message = 'New Case Created';
        result.success = true;
        return result; // return Result
    }
}

That's all, comment below If you need any help

Phanindra Mangipudi

Salesforce, Lightning Web Componets, Node.Js, Angular 2+, Bootstrap