You need to sign in to do that
Don't have an account?
Ritchieb
Help with Test class for Page redirect Apex class
Hi All,
I am new to apex code and have managed. to get an apex class to redirect profiles to two different pages dependent on an if statement. I now need to create a test class. Would anyone be able to help create one?
Here is the code;
public class overrideCon {
String recordId;
public overrideCon(ApexPages.StandardController
controller) {recordId = controller.getId();}
public PageReference redirect() {
Profile p = [select name from Profile where id =
:UserInfo.getProfileId()];
if ('Customer Portal User'.equals(p.name)
|| 'Partner Portal User'.equals(p.name)
|| 'Customer Portal Manager Custom'.equals(p.name))
{
//If Portal User show Portal Page
PageReference customPage = Page.portalCasePage;
customPage.setRedirect(true);
customPage.getParameters().put('id', recordId);
return customPage;
} else {
//If NOT Portal User show Standard Page
PageReference customPage2 = Page.standardCasePage;
customPage2.setRedirect(true);
customPage2.getParameters().put('id', recordId);
return customPage2;
}
}
}
Hi,
Steps
1 Retrive Users from your instance.
2.Then call your methods with in the scope of the System.runas("userid").
That should do it.
for further details follw this link -http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_testing_example.htm
Regards,
Manjunath