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
tunedogtunedog 

Redirect Extension Test Method

Can anyone give me some pointers on how to write a test method for this redirect extension?

Thanks in advance for any help!


 

public with sharing class aquavistaRedirect {

	PageReference rd= new PageReference('http://www.prmaustralia.com.au/MAB/Aquavista_Thankyou.html');
	
	    ApexPages.StandardController controller;
    public aquavistaRedirect(ApexPages.StandardController con){
        controller = con;
     }            
 
    public PageReference save() {
        controller.save();
        return rd;
    }

}

 

Best Answer chosen by Admin (Salesforce Developers) 
bob_buzzardbob_buzzard

You haven't said which standard controller this is an extension to - I've assumed account but if that's not the case just replace the correct type in the constructor:

 

 

private static testMethod void testRedirect()
{
    aquavistaRedirect controller=new aquavistaRedirect(
        new ApexPages.StandardController(
                        new Account()));
    PageReference pr=controller.save();

    System.assertNotEquals(-1, pr.getUrl().indexOf('prmaustralia'));    
}

 

I haven't compile this, so there may be the odd typo, but hopefully you get the picture.