+ Start a Discussion
Simon234Simon234 

Static method cannot be referenced from a non static context (PageReference)

It's a test block for my VF Controller. What is wrong here?
Candidate__c cand = new Candidate__c();
    insert cand;

    PageReference pageRef = Page.UploadCandidatePhotoVF;
        Test.startTest();
        Test.setCurrentPage(pageRef);
        pageRef.getParameters().put('id', cand.Id);
        ApexPages.StandardController stdController = new ApexPages.StandardController(cand);
        FileUploaderController fileUploader = new FileUploaderController(stdController);
        fileUploader.uploadFile();
        Test.stopTest();

 
Best Answer chosen by Simon234
Raj VakatiRaj Vakati
I believe its must be like below .. what is  the method synatx for uploadFile
 
Candidate__c cand = new Candidate__c();
    insert cand;

    PageReference pageRef = Page.UploadCandidatePhotoVF;
        Test.startTest();
        Test.setCurrentPage(pageRef);
        pageRef.getParameters().put('id', cand.Id);
        ApexPages.StandardController stdController = new ApexPages.StandardController(cand);
        FileUploaderController fileUploader = new FileUploaderController(stdController);
        FileUploaderController.uploadFile();
        Test.stopTest();

 

All Answers

Raj VakatiRaj Vakati
I believe its must be like below .. what is  the method synatx for uploadFile
 
Candidate__c cand = new Candidate__c();
    insert cand;

    PageReference pageRef = Page.UploadCandidatePhotoVF;
        Test.startTest();
        Test.setCurrentPage(pageRef);
        pageRef.getParameters().put('id', cand.Id);
        ApexPages.StandardController stdController = new ApexPages.StandardController(cand);
        FileUploaderController fileUploader = new FileUploaderController(stdController);
        FileUploaderController.uploadFile();
        Test.stopTest();

 
This was selected as the best answer
Bryan Leaman 6Bryan Leaman 6
It would help to see more of the test class, the full error message and the declarations of the referenced FileUploaderController class & methods.

For example, if you try to reference getParameters directly on the PageReference class, you'll get an error similar to what you have in your subject. I got this from a 1-line anonymous apex:
System.debug(PageReference.getParameters());

Compile error at line 1 column 28
Non static method cannot be referenced from a static context: Map<String,String> System.PageReference.getParameters()