• emma jane
  • NEWBIE
  • 0 Points
  • Member since 2020

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
    Questions
  • 1
    Replies
Hey Guys!

Although I have >95% code coverage, however, I'd still like to get it to 100% and need some guidance with the following :)

How would you enter the Exception block below via Test Class? Passing an empty string to method1 probably won't work. Any other ideas that would force this to happen?
public class SomeClass {
    
    public static void method1(List<String> strings) {
        List<SObject> sObjects = [Select Id, Name FROM SObject WHERE Id IN :strings];
        if (sObjects.size() > 0) {
            for (SObject sObj : sObjects) {
                try {
                    method2(sObj);
                } catch (Exception ex) {
                    System.debug('***EXCEPTION***');
                    ex.getStackTraceString();
                }
            } 
        }
    }

    public static void method2(SObject sObj) {
        //Do something here
    }
}
Any help would be appreciated. Thanks!
 
  • February 03, 2020
  • Like
  • 0