• Maze Linn
  • NEWBIE
  • 10 Points
  • Member since 2019

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 0
    Replies
I am trying to write test coverage for a method and receiving the error "Attempt to de-reference a null object" when I run the test.  Below is my test class, can anyone guide me in the right direction with this?

Test class:

static testmethod void getselectOptionsTest(){
        Id RecordTypeIdPropAccount = Schema.SObjectType.Account.getRecordTypeInfosByName().get('Franchisee').getRecordTypeId();
        
        Account fAcct = new Account(Name = 'Test', RecordTypeId=RecordTypeIdPropAccount);
        insert fAcct;
        sObject objObject = [SELECT Id, Name FROM Account WHERE Name = 'Test' LIMIT 1];
        String fld = 'RetailerCategory';
        
        Test.startTest();
        multiPicklistCtrl.getselectOptions(objObject, fld);
        Test.stopTest();
        
    }

Original method:

@AuraEnabled
    public static List <String> getselectOptions(sObject objObject, string fld) {
          system.debug('objObject --->' + objObject);
          system.debug('fld --->' + fld);
          List < String > allCats = new list < String > ();
          // Get the object type of the SObject.
          Schema.sObjectType objType = objObject.getSObjectType();
        
        // Describe the SObject using its object type.
          Schema.DescribeSObjectResult objDescribe = objType.getDescribe();
 
          // Get a map of fields for the SObject
          map < String, Schema.SObjectField > fieldMap = objDescribe.fields.getMap();

          // Get the list of picklist values for this field.
          list < Schema.PicklistEntry > values =
           fieldMap.get(fld).getDescribe().getPickListValues();

          // Add these values to the selectoption list.
          for (Schema.PicklistEntry a: values) {
           allCats.add(a.getValue());
          }
          system.debug('allCats ---->' + allCats);
          allCats.sort();
          return allCats;    
        }