Skip to main content
Matthias Kuich が「#Apex」で質問

My goal is to dynamically load email templates depending on the recordtype of the case.

I followed this documentation(https://help.salesforce.com/s/articleView?id=sf.case_interaction_default_templates.htm&type=5) and checked the box under support settings and created an Apex class according to the template from(https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_email_template_selector.htm).

The test class runs correctly, but when I write an email in the case feed, the apex class is not called. No template is loaded. It is also not visible in the debug log that the apex class is called. It looks like another setting is needed, which is not in the documentation.

When opening a case and clicking on email compose in the chatter feed not template is selected.

I hope you can help me.

Apex Class:

 

global class MyCaseTemplateChooser implements Support.EmailTemplateSelector {

// Empty constructor

global MyCaseTemplateChooser() { }

// The main interface method

global ID getDefaultEmailTemplateId(ID caseId) {

System.debug('getDefaultEmailTemplateId '+caseId);

// Select the case we're interested in, choosing any fields that are relevant to our decision

Case c = [SELECT RecordType.DeveloperName FROM Case WHERE Id=:caseId];

System.debug('c '+c);

System.debug('recordTypedevelopername '+c.RecordType.DeveloperName);

EmailTemplate et;

if (c.RecordType.DeveloperName == 'Internal_case') {

et = [SELECT id FROM EmailTemplate WHERE DeveloperName = 'Service_EN_intern_1560873626626'];

System.debug('return template id '+et.id);

}else{

return null;

}

// Return the ID of the template selected

return et.id;

}

}

Test Class:

@isTest

private class MyCaseTemplateChooserTest {

@isTest

static void testChooseTemplate() {

MyCaseTemplateChooser chooser = new MyCaseTemplateChooser();

//get recordtypes

ID internalCaseId = [SELECT Id from RecordType where DeveloperName = 'Internal_case'].id;

ID technicalSupportCaseId = [SELECT Id from RecordType where DeveloperName = 'technical_support'].id;

// Create a simulated case to test with

Case c1 = new Case();

c1.Subject = 'test 1 internal case';

c1.recordtypeId = internalCaseId;

insert c1;

Case c2 = new Case();

c2.Subject = 'test 2 Technical Support case';

c2.recordtypeId = technicalSupportCaseId;

insert c2;

// Make sure the proper template is chosen for this subject

Id actualTemplateId = chooser.getDefaultEmailTemplateId(c1.Id);

EmailTemplate expectedTemplate = [SELECT id FROM EmailTemplate WHERE DeveloperName = 'Service_EN_intern_1560873626626'];

Id expectedTemplateId = expectedTemplate.Id;

System.assertEquals(actualTemplateId, expectedTemplateId);

// Make sure the correct template is chosen in this case

actualTemplateId = chooser.getDefaultEmailTemplateId(c2.Id);

expectedTemplateId = expectedTemplate.Id;

System.assertNotEquals(actualTemplateId, expectedTemplateId);

}

}

This are the settings under support settings

Enable Default Email Templates in Case Feed not working
2 件の回答
0/9000