---
schema_version: "1"
id: 6c8825a5ab21878b6cfcdba874d347325996e4a4b49f8490f54707bbb058cd22
title: EmailTemplateSelector Interface
collection: legacydeveloper
version: current
locale: en-us
portal_url: https://docs.salesforce.com/legacydeveloper/current/en-us/apexref/apex_email_template_selector.md
canonical_url: https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_email_template_selector.htm
source_site: developer.salesforce.com
content_type: documentation
content_hash: 3c09959ad05f0a3d227f9c2da005439fa943497827f48140921275be03b672f2
description: The Support.EmailTemplateSelector interface enables providing default email templates in Case Feed. With default email templates, specified email templates are preloaded for cases based on criteria such as case origin or subject. Returns the ID of the email template to preload for the case currently being viewed in the case feed using the specified case ID.
---
# EmailTemplateSelector Interface

The Support.EmailTemplateSelector interface enables providing default email templates in Case Feed. With default email templates, specified email templates are preloaded for cases based on criteria such as case origin or subject.

Support.EmailTemplateSelector works only in Salesforce Classic, not in Lightning Experience. Lightning Experience users can specify default values for emails using the QuickActionDefaultsHandler interface.

## Namespace

[Support](https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_namespace_Support.htm "The Support namespace provides an interface used for Case Feed.")

To specify default templates, you must create a class that implements Support.EmailTemplateSelector.

When you implement this interface, provide an empty parameterless constructor.

- **[EmailTemplateSelector Methods](https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_email_template_selector.htm#apex_Support_EmailTemplateSelector_methods)**
- **[EmailTemplateSelector Example Implementation](https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_email_template_selector.htm#apex_email_template_selector_example)**

## EmailTemplateSelector Methods

The following are methods for EmailTemplateSelector.

- **[getDefaultTemplateId(caseId)](https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_email_template_selector.htm#apex_Support_EmailTemplateSelector_getDefaultTemplateId)**  
    Returns the ID of the email template to preload for the case currently being viewed in the case feed using the specified case ID.

### getDefaultTemplateId(caseId)

Returns the ID of the email template to preload for the case currently being viewed in the case feed using the specified case ID.

#### Signature

public ID getDefaultTemplateId(ID caseId)

#### Parameters

- **caseId**:
    
    Type: [ID](https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_methods_system_id.htm#apex_methods_system_id "Contains methods for the ID primitive data type.")

#### Return Value

Type: [ID](https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_methods_system_id.htm#apex_methods_system_id "Contains methods for the ID primitive data type.")

## EmailTemplateSelector Example Implementation

This is an example implementation of the Support.EmailTemplateSelector interface.

The getDefaultEmailTemplateId method implementation retrieves the subject and description of the case corresponding to the specified case ID. Next, it selects an email template based on the case subject and returns the email template ID.

public with sharing class MyCaseTemplateChooser implements Support.EmailTemplateSelector {
    // Empty constructor 
    public MyCaseTemplateChooser() {    }

    // The main interface method 
    =public ID getDefaultEmailTemplateId(ID caseId) {
        // Select the case we're interested in, choosing any fields that are relevant to our decision
        Case c = \[SELECT Subject, Description FROM Case WHERE Id=:caseId WITH USER\_MODE\];

        EmailTemplate et;

        if (c.subject.contains('LX-1150')) {
            et = \[SELECT id FROM EmailTemplate WHERE DeveloperName = 'LX1150\_template' WITH USER\_MODE\];
        } else if(c.subject.contains('LX-1220')) {
            et = \[SELECT id FROM EmailTemplate WHERE DeveloperName = 'LX1220\_template' WITH USER\_MODE\];
        } 
        
        // Return the ID of the template selected
        return et.id;
    }
} 

The following example tests the above code:

@IsTest
private with sharing class MyCaseTemplateChooserTest {

    @IsTest
    static void testChooseTemplate() {
    
        MyCaseTemplateChooser chooser = new MyCaseTemplateChooser();

        // Create a simulated case to test with
        Case c = new Case();
        c.Subject = 'I\\'m having trouble with my LX-1150';
        Database.insert(c, AccessLevel.USER\_MODE);
            
        // Make sure the proper template is chosen for this subject
        Id actualTemplateId = chooser.getDefaultEmailTemplateId(c.Id);
        EmailTemplate expectedTemplate = 
          \[SELECT id FROM EmailTemplate WHERE DeveloperName = 'LX1150\_template' WITH USER\_MODE\];
        Id expectedTemplateId = expectedTemplate.Id;
        Assert.areEqual(expectedTemplateId, actualTemplateId);
  
        // Change the case properties to match a different template
        c.Subject = 'My LX1220 is overheating';
        Database.update(c, AccessLevel.USER\_MODE);
  
        // Make sure the correct template is chosen in this case
       actualTemplateId = chooser.getDefaultEmailTemplateId(c.Id);
        expectedTemplate = 
          \[SELECT id FROM EmailTemplate WHERE DeveloperName = 'LX1220\_template' WITH USER\_MODE\];
        expectedTemplateId = expectedTemplate.Id;
        Assert.areEqual(expectedTemplateId, actualTemplateId);
    
    }
}