No Results
Search Tips:
- Please consider misspellings
- Try different search keywords
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");global class MyCaseTemplateChooser implements Support.EmailTemplateSelector {
2 // Empty constructor
3 global MyCaseTemplateChooser() { }
4
5 // The main interface method
6 global ID getDefaultEmailTemplateId(ID caseId) {
7 // Select the case we're interested in, choosing any fields that are relevant to our decision
8 Case c = [SELECT Subject, Description FROM Case WHERE Id=:caseId];
9
10 EmailTemplate et;
11
12 if (c.subject.contains('LX-1150')) {
13 et = [SELECT id FROM EmailTemplate WHERE DeveloperName = 'LX1150_template'];
14 } else if(c.subject.contains('LX-1220')) {
15 et = [SELECT id FROM EmailTemplate WHERE DeveloperName = 'LX1220_template'];
16 }
17
18 // Return the ID of the template selected
19 return et.id;
20 }
21} The following example tests the above code:
1swfobject.registerObject("clippy.codeblock-1", "9");@isTest
2private class MyCaseTemplateChooserTest {
3
4 static testMethod void testChooseTemplate() {
5
6 MyCaseTemplateChooser chooser = new MyCaseTemplateChooser();
7
8 // Create a simulated case to test with
9 Case c = new Case();
10 c.Subject = 'I\'m having trouble with my LX-1150';
11 Database.insert(c);
12
13 // Make sure the proper template is chosen for this subject
14 Id actualTemplateId = chooser.getDefaultEmailTemplateId(c.Id);
15 EmailTemplate expectedTemplate =
16 [SELECT id FROM EmailTemplate WHERE DeveloperName = 'LX1150_template'];
17 Id expectedTemplateId = expectedTemplate.Id;
18 System.assertEquals(actualTemplateId, expectedTemplateId);
19
20 // Change the case properties to match a different template
21 c.Subject = 'My LX1220 is overheating';
22 Database.update(c);
23
24 // Make sure the correct template is chosen in this case
25 actualTemplateId = chooser.getDefaultEmailTemplateId(c.Id);
26 expectedTemplate =
27 [SELECT id FROM EmailTemplate WHERE DeveloperName = 'LX1220_template'];
28 expectedTemplateId = expectedTemplate.Id;
29 System.assertEquals(actualTemplateId, expectedTemplateId);
30
31 }
32}