1

I have a Controller, roughly as follows:

global with sharing class MyController extends OtherController {

    public static List<Task> getTaskList() {            
        //SOME LOGIC    
    }

}

And a unit test for that controller:

@isTest
private class MyControllerTest{

    @isTest 
    static void testGetTaskList() {

        Test.startTest();                

        try {
            List<Task> myTask = MyController.getTaskList();                       
            System.assert(false, 'Did not do it's job);
        } catch (Exception ex) {
            System.assertEquals('Error', ex.getTypeName());
        }

        Test.stopTest(); 
    }

}

When I try and save my test class, I get the following error:

Save error: Method does not exist or incorrect signature: MyController.getTaskList()

I really can't see what the issue is here at all, can anyone help me out??

2

You're attempting to reference the method like its a static method which it isn't. You either need to change the method to be static or instantiate your controller first.

3
  • Cheers for the response Phil, Ive made my method static but still the same error. – Daft Jul 15 '14 at 14:43
  • 1
    @Daft The code you have posted does compile with the string changed to 'Did not do its job' and 'extends OtherController' removed (as you didn't post that class) so your problem must lie in some code you have not posted. – Keith C Jul 15 '14 at 14:51
  • I had stupidly left out a variable which was to be passed into the method in my controller. Phil's suggestion to make it static was correct. As was @KeithC's that the problem was elsewhere in code I had not posted. Thanks a lot guys! – Daft Jul 15 '14 at 14:56

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.