You need to sign in to do that
Don't have an account?

Need help with Test class
Hi,
I have issues in writing test class for below copntroller.
I have issues in writing test class for below copntroller.
public class EditContacts { ApexPages.StandardSetController setCon; List<string> strIds = new List<string>(); List<Contact> lstContact = new List<Contact>(); public integer size {get;set;} public final String URL {get;set;} public Contact c; public Contact getNewContact() { if(c==null)c= new Contact(); return c; } public MassEditContacts (Apexpages.Standardsetcontroller cont) { setCon = cont; strIds = ApexPages.currentPage().getParameters().get('recs').split(',',-2); size = strIds.size(); URL = ApexPages.currentPage().getURL(); } public List<Contact> getContacts() { lstContact = [select Name, Title, Phone, MobilePhone, Email, AccountId, ownerid from Contact where id IN: strIds ]; return lstContact; } public Pagereference saveRecords() { List<Contact> updateContact = new List<Contact>(); for(Contact cse : lstContact) { updateContact.add(cse); } update updateContact; return new Pagereference('/'+Contact.getSObjectType().getDescribe().getKeyPrefix()+'/o'); } public Pagereference ccancel() { system.debug('***ccancel**'); return new Pagereference('/'+Contact.getSObjectType().getDescribe().getKeyPrefix()+'/o'); } }
//Create all the test Data
//Call Controller
//Set Visualforce Page
//Call Controller Methods
//Assert Methods perform expected output
You can see a generic example of testing a visualforce controller here: http://www.salesforce.com/us/developer/docs/pages/Content/pages_controller_error_handling.htm
The one it doesn't do is create any test data. But that's works just like creating a new record outside of a test. Just make sure you create all the data you need since your test won't see any actual live data (and you don't want it to)
So you'll need to instantiate a StandardSetController first (which takes a list of sobjects and not a single sobject).
For instance, the following should solve the error above: