You need to sign in to do that
Don't have an account?
Barrie Potter
Help with Test for Extension
I would really apprecitate some assitance here getting this test to work right. I am not a developer but I am trying!
Here is my Controller Extension
And here is my test
Here is my Controller Extension
public with sharing class ContactSaveEXT { ApexPages.StandardController controller; public ContactSaveEXT (ApexPages.StandardController controller) { this.controller = controller; } public PageReference doSaveAndRedirect() { this.controller.save(); PageReference redirect = new PageReference('https://c.cs43.visual.force.com/apex/Thankyoupage?core.apexpages.request.devconsole=1'); return redirect; } }
And here is my test
@isTest public class ContactSaveExt_Test { static testmethod void test() { //create Account Account testAccount = new Account(); testAccount.Name='Test Account' ; insert testAccount; //Create Contact Contact con= new contact(); con.Email = 'Test@gmail.com'; con.LastName= 'TodayTest'; con.FirstName= 'Test'; con.Id = con.Id; insert con; //create pageReference PageReference page = new PageReference('/apex/AdultVolunteerWaiver'); Test.setCurrentPage(page); //pass parameter to the page ApexPages.currentPage().getParameters().put('id',con.Id); ApexPages.currentPage().getParameters().put('FirstName',con.FirstName); ApexPages.currentPage().getParameters().put('LastName',con.LastName); ApexPages.currentPage().getParameters().put('Email',con.Email); //create an instance of controller. ApexPages.StandardController standrdcontroller = new ApexPages.StandardController(con); ContactSaveExt clsInstance = new ContactSaveExt(standrdcontroller); } }
Try to update your class like below
Or you can try below class as well
Let us know if this will help you