I generate a number of different email notifications from Cases, with variations depending on Account location, for example. They've morphed from basic workflow email templates in order to gather details from Assets, Contacts, etc., and I've been working in standard processes/methods 'cause maintenance is hell.

I've built generic utility classes before, and am trying to create one specifically for these notifications, but if there's a better approach now's the time.

My Utils class is defined like this:

    global class Utils {

       public static List<Contact> getActiveContactsByAccountIdRTId(Set<Id> accountIds, Set<Id> rtIds) {

          List<Contact> results;        
          results = [some query];
          return results;

It made sense to me to separate the notification methods and treat them the same way, but a) I'm getting that 'cannot call test methods in non-test context' error, and also b) Should I take a moment (or several) and create an abstract class for the notification template so to speak, and build out any customizations in the derived classes?

I have a good example to work from which uses SObject recordtypes to determine which path to follow, and I'll need to work out a different set of criteria for routing these Cases through.

  • 1
    Search for and remove spurious @IsTest or testMethod to solve the problem in the title. The non-test code must not invoke any test method. – Keith C Jan 17 '18 at 17:28
  • The methods were not test methods / in a test class - they're in a global class as indicated in the snippet. Rather than add to my existing Utils class, I created a new Global class called NotificationUtils, and created public static methods in the new class, and called them from a separate non-test class, but still received that error. – Duncan Stewart Jan 18 '18 at 19:57
  • Are you sure there are no other methods being called i.e. the NotificationUtils and separate non-test class make no references to utility methods or base class methods? Would be worth turning on debug logging and checking there too. – Keith C Jan 18 '18 at 20:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.