You need to sign in to do that
Don't have an account?
Andy Kallio 13
Admin looking for help with QuickActionDefaults test coverage
Hello friends
I'm working with the QuickActionDefaultsHandler interface for the first time.
Just following the example set here:
https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_interface_QuickAction_QuickActionDefaultsHandler.htm#apex_interface_QuickAction_QuickActionDefaultsHandler
I think I have what I want and now trying to write a test class which is turning about to be challenging.
Now as you can see in the class there is an if statement tests for the actiontype being 'SendEmail'
defaults.get(j).getActionType().equals('SendEmail'))
And this works with the testing that I have done in the UI, but it does not work in my test class. For some reason in my test class the debug logs are showing that method is returning 'Email' and therefore not getting past the if statement.
I don't understand why there is a difference, or see what I can do to fix it.
Class:
Test Class:
I'm working with the QuickActionDefaultsHandler interface for the first time.
Just following the example set here:
https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_interface_QuickAction_QuickActionDefaultsHandler.htm#apex_interface_QuickAction_QuickActionDefaultsHandler
I think I have what I want and now trying to write a test class which is turning about to be challenging.
Now as you can see in the class there is an if statement tests for the actiontype being 'SendEmail'
defaults.get(j).getActionType().equals('SendEmail'))
And this works with the testing that I have done in the UI, but it does not work in my test class. For some reason in my test class the debug logs are showing that method is returning 'Email' and therefore not getting past the if statement.
I don't understand why there is a difference, or see what I can do to fix it.
Class:
global class EmailPublisherLoader implements QuickAction.QuickActionDefaultsHandler { // The main interface method global void onInitDefaults(QuickAction.QuickActionDefaults[] defaults) { QuickAction.SendEmailQuickActionDefaults sendEmailDefaults = null; system.debug('defaults '+defaults); // Check if the quick action is the standard Case Feed send email action for (Integer j = 0; j < defaults.size(); j++) { system.debug('sobject: '+defaults.get(j).getTargetSObject().getSObjectType()); system.debug('Name: '+defaults.get(j).getActionName()); system.debug('Type: '+defaults.get(j).getActionType()); if (defaults.get(j) instanceof QuickAction.SendEmailQuickActionDefaults && defaults.get(j).getTargetSObject().getSObjectType() == EmailMessage.sObjectType && defaults.get(j).getActionType().equals('SendEmail')) { sendEmailDefaults = (QuickAction.SendEmailQuickActionDefaults)defaults.get(j); system.debug('defaults: '+sendEmailDefaults); break; } } if (sendEmailDefaults != null) { Case c = [SELECT Status, Contact.Email, RecordType.Name, Origin, Service_Email__c FROM Case WHERE Id=:sendEmailDefaults.getContextId()]; EmailMessage emailMessage = (EmailMessage)sendEmailDefaults.getTargetSObject(); system.debug('in reply to: '+sendEmailDefaults.getInReplyToId()); //if replying to an email then use original emails subject and include the original email if(sendEmailDefaults.getInReplyToId() == null) { sendEmailDefaults.setInsertTemplateBody(false); sendEmailDefaults.setIgnoreTemplateSubject(false); } else { sendEmailDefaults.setInsertTemplateBody(true); sendEmailDefaults.setIgnoreTemplateSubject(true); } sendEmailDefaults.setTemplateId(getTemplateIdHelper(c.service_email__c)); } } private Id getTemplateIdHelper(String serviceEmail) { Id templateId = null; try { templateId = [select id, Email_Template_Id__c from Case_Feed_Default_Email_Template__mdt where Service_Email__c = :serviceEmail limit 1].Email_Template_Id__c; } catch (Exception e) { system.debug('Unble to locate EmailTemplate using name: ' + serviceEmail + ' refer to Setup | Communications Templates ' + serviceEmail); } return templateId; } }
Test Class:
@isTest public class EmailPublisherLoader_Test { static testMethod void rbnCustomer() { //setup test data boolean doInsert = true; case_TestData_Director director = new case_TestData_Director(); Case cs = director.construct(new case_TestData_RBNCustomer(), doInsert); list<QuickAction.QuickActionDefaults> defaults = new list<QuickAction.QuickActionDefaults>(); QuickAction.SendEmailQuickActionDefaults sendEmailDefaults = Test.newSendEmailQuickActionDefaults(cs.Id, null); defaults.add(sendEmailDefaults); Test.startTest(); EmailPublisherLoader cntl = new EmailPublisherLoader(); cntl.onInitDefaults(defaults); Test.stopTest(); EmailMessage emailMessage = (EmailMessage) sendEmailDefaults.getTargetSObject(); System.assertNotEquals(null, emailMessage); } }