You need to sign in to do that
Don't have an account?
Liz Gibbons 16
Test class for controller with PageReference
Hello, I am working on writing a test class for a custom controller that creates an Account list, and then based on the selected Account's ID, redirects to a new page. I'm new to this so any help would be appreciated.
Controller:
Test class:
Am I at least on the right path?
Controller:
public without sharing class SDPController { public List<Account> PAISchools = new List<Account>(); public SDPController(){ } public List<SelectOption> PAIList{ get{ PAISchools = [Select Account.Name, Account.Id From Account Where Account.ParentId = '0011700000BZkKR']; PAIList = new List<SelectOption>(); for(Account temp : PAISchools){ PAIList.add(new SelectOption(temp.id, temp.Name)); } return PAIList; } set; } public String idString{get;set;} public PageReference saveform(){ update PAISchools ; // helps in saving the record PageReference pageRef = new PageReference('https://dev2-dor.cs22.force.com/eportfolio/LPRegistration?code='+idString+''); pageRef.setRedirect(true); return pageRef; } public PageReference signin(){ PageReference signIn = new PageReference('https://dev2-dor.cs22.force.com/eportfolio/motivislp__LPSignIn'); signIn.setRedirect(true); return signIn; } }
Test class:
@isTest public class TestSDPController { public static testMethod void testSDP() { Account acc = new Account(name= 'Testing', ParentId= '0011700000BZkKR'); insert acc; Test.startTest(); PageReference testPage = Page.SchoolSelect2; Test.setCurrentPage(testPage); testPage.getUrl(); SDPController sdp = new SDPController(); sdp.saveform(); Test.stopTest(); } }
Am I at least on the right path?
code below, with comments inside: Hope it will help a little bit.
Marek
All Answers
code below, with comments inside: Hope it will help a little bit.
Marek