function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Daniel Neufeld 6Daniel Neufeld 6 

How do I test a public class that references a VF page?

I'm new to Apex and trying to achieve code coverage for an Apex Class that references a VF page. Below is my apex class: 
 
public class Wave_Sales_Performance{
 public PageReference saveMethod()
    {
  PageReference pgref = new PageReference('https://c.na26.visual.force.com/apex/Wave_Sales_Performance');
        pgref.setRedirect(true);
        return pgref;
        
    }
    public PageReference saveMethod2()
    {
  PageReference pgref = new PageReference('https://c.na26.visual.force.com//apex/Wave_New_Rev_by_Individual');
        pgref.setRedirect(true);
        return pgref;
    }    
        public PageReference saveMethod3()
    {
  PageReference pgref = new PageReference('https://c.na26.visual.force.com/apex/Wave_YTD_Appointment_Metrics');
        pgref.setRedirect(true);
        return pgref;
       } 
        public PageReference saveMethod4()
    {
  PageReference pgref = new PageReference('https://c.na26.visual.force.com/apex/Wave_Online_Offline');
        pgref.setRedirect(true);
        return pgref;
       } 
         public PageReference saveMethod5()
    {
  PageReference pgref = new PageReference('https://c.na26.visual.force.com/apex/Wave_Actual_Budget');
        pgref.setRedirect(true);
        return pgref;
       } 
        
    
}


Any solutions or advice would be much appreciated. 

Thanks
Daniel

Best Answer chosen by Daniel Neufeld 6
Dilip_VDilip_V
Daniel,

Refer this link:
https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_qs_test.htm
@isTest 
private class HelloWorldTestClass {
    static testMethod void validateHelloWorld() {
     Wave_Sales_Performance WSP=new Wave_Sales_Performance();
     WSP.saveMethod();
WSP.saveMethod2();
WSP.saveMethod3();
WSP.saveMethod4();
WSP.saveMethod5();

    }
}


Let us know if you have any issues.

Mark it as best answer if it works.

Thanks.

All Answers

Dilip_VDilip_V
Hi Daniel,

Just like any other class.
1.Create instance.
Wave_Sales_Performance WSP=new Wave_Sales_Performance();
2.Call methods with instance.
WSP.saveMethod();

Let us know if you have any issues.

Mark it as best answer if it works.

Thanks.
Dilip_VDilip_V
Daniel,

Refer this link:
https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_qs_test.htm
@isTest 
private class HelloWorldTestClass {
    static testMethod void validateHelloWorld() {
     Wave_Sales_Performance WSP=new Wave_Sales_Performance();
     WSP.saveMethod();
WSP.saveMethod2();
WSP.saveMethod3();
WSP.saveMethod4();
WSP.saveMethod5();

    }
}


Let us know if you have any issues.

Mark it as best answer if it works.

Thanks.
This was selected as the best answer
Daniel Neufeld 6Daniel Neufeld 6
Thank you so much Dillup! I thought there was more to it then that. Will definitely review that link. Thanks again.