-3

I am having hard time to write test class for following method any help would be appreciated.

Controller class:

 public static List<ListView> getListViews(){        
    List<ListView> listviews = new List<ListView>();
    for(ListView lstObj : [SELECT Id, Name FROM ListView WHERE SobjectType   = 'Custom__c' order by name ASC]){
     listviews.add(lstObj);
    }    
    return listviews;
 }

Thanks!

1
  • 3
    please include where in your test class you are stuck, if you are not at all familiar with unit testing, I would recommend you start with Trailheads, read the documentation and then update your p ost with what exactly you are having trouble and/or dont seem to understand.
    – glls
    Jul 23, 2018 at 20:15

1 Answer 1

2

First of all, the method should be written like this:

public static List<ListView> getListViews(){        
  return [SELECT Name FROM ListView WHERE SobjectType = 'Custom__c' order by Name];
}

Second, to call a static method, just specify the name of the class followed by the method name:

List<ListView> views = MyClass.getListViews();

Not the answer you're looking for? Browse other questions tagged .