Newer Version Available
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.
Namespace
To specify default templates, you must create a class that implements Support.EmailTemplateSelector.
When you implement this interface, provide an empty parameterless constructor.
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.
1swfobject.registerObject("clippy.codeblock-0", "9");
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17global class MyCaseTemplateChooser implements Support.EmailTemplateSelector {
18 // Empty constructor
19 global MyCaseTemplateChooser() { }
20
21 // The main interface method
22 global ID getDefaultEmailTemplateId(ID caseId) {
23 // Select the case we're interested in, choosing any fields that are relevant to our decision
24 Case c = [SELECT Subject, Description FROM Case WHERE Id=:caseId];
25
26 EmailTemplate et;
27
28 if (c.subject.contains('LX-1150')) {
29 et = [SELECT id FROM EmailTemplate WHERE DeveloperName = 'LX1150_template'];
30 } else if(c.subject.contains('LX-1220')) {
31 et = [SELECT id FROM EmailTemplate WHERE DeveloperName = 'LX1220_template'];
32 }
33
34 // Return the ID of the template selected
35 return et.id;
36 }
37} The following example tests the above code:
1swfobject.registerObject("clippy.codeblock-1", "9");
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17@isTest
18private class MyCaseTemplateChooserTest {
19
20 static testMethod void testChooseTemplate() {
21
22 MyCaseTemplateChooser chooser = new MyCaseTemplateChooser();
23
24 // Create a simulated case to test with
25 Case c = new Case();
26 c.Subject = 'I\'m having trouble with my LX-1150';
27 Database.insert(c);
28
29 // Make sure the proper template is chosen for this subject
30 Id actualTemplateId = chooser.getDefaultEmailTemplateId(c.Id);
31 EmailTemplate expectedTemplate =
32 [SELECT id FROM EmailTemplate WHERE DeveloperName = 'LX1150_template'];
33 Id expectedTemplateId = expectedTemplate.Id;
34 System.assertEquals(actualTemplateId, expectedTemplateId);
35
36 // Change the case properties to match a different template
37 c.Subject = 'My LX1220 is overheating';
38 Database.update(c);
39
40 // Make sure the correct template is chosen in this case
41 actualTemplateId = chooser.getDefaultEmailTemplateId(c.Id);
42 expectedTemplate =
43 [SELECT id FROM EmailTemplate WHERE DeveloperName = 'LX1220_template'];
44 expectedTemplateId = expectedTemplate.Id;
45 System.assertEquals(actualTemplateId, expectedTemplateId);
46
47 }
48}