You need to sign in to do that
Don't have an account?
Test class 75% covered help needed in covering remaining percent
Hi i am trying to learn unit testing in salesforce. Below is the code of my controller class. The lines marked as red are not getting covered, can any one suggest me how to do it ? Thanks in advance.
public class RadioButton {
public List<contact> selectcon=new List<contact>();
contact con;
public string selectconid;
Public List<contact> getAllContacts()
{
List<contact> allcons = [Select Id,FirstName,LastName,Email,Phone from Contact LIMIT 10];
return allcons;
}
Public void selectcon()
{
string selectconid = System.currentPagereference().getParameters().get('conid');
con = [Select Id,FirstName,LastName,Email,Phone from Contact where Id=:selectconid limit 1];
selectcon.add(con);
}
Public List<contact> getselectedContact()
{
return selectcon;
}
}
Hi Hussain,
Below is the sample code for your test class.
Test Class:
Important :
Hit Kudos if this provides you with useful information and if this is what you where looking for then please mark it as a solution for other benefits.
Thank You,
Hitesh Patel
SFDC Certified Developer & Administrator & Sales cloud consultant
My Blog:- http://mrjavascript.blogspot.in/
All Answers
Hussain,
Are you setting a contact id to the current page parameter 'conid'? If not you will have to set it in your test class.
It is trying to get a contact record where it matches with the page parameter Id, which I guess is returning null.
Hi Hussain,
Below is the sample code for your test class.
Test Class:
Important :
Hit Kudos if this provides you with useful information and if this is what you where looking for then please mark it as a solution for other benefits.
Thank You,
Hitesh Patel
SFDC Certified Developer & Administrator & Sales cloud consultant
My Blog:- http://mrjavascript.blogspot.in/
Yes i am getting system.query exception:List has no rows for assignment to sobject error.