+ Start a Discussion
Amita TatarAmita Tatar 

test class coder coverage issue

Hi all,

I have a test class and i am not able to increase its code coverage.
I am posting my apex class and test class code.
Apex Class----------------------------------------

public class DisplayNotesNew{

public List<WrapperClass> listWrapper {get;set;}
public List<ContactWrapper> listWrapper1 {get;set;}
public List<OpportunityWrapper> listWrapper2 {get;set;}
public Id accId;
Public Account acc;
public List<Note> selectedNotes{get;set;}
public List<Contact> selectedContacts{get;set;}
public List<opportunity> selectedOpps{get;set;}
List<note> contactNote = new List<note>();
List<note> oppNote = new List<note>();
public ID noteID {get;set;}
Public String getRadioValue{get;set;}

public void assignNoteId() {
   Id note = ApexPages.currentPage().getParameters().get('note');
   system.debug('18-->'+note );
   if(note != null) {
      noteID = note;

public DisplayNotesNew(){
public DisplayNotesNew(ApexPages.StandardController Controller) {

accId = ApexPages.currentPage().getParameters().get('id');
List<Note> listAcct = [SELECT Id,Title, Body,Parent.Id,CreatedDate FROM Note where Parent.Id =: accId order by ID DESC];
  if(listAcct.size() > 0) {
    listWrapper = new List<WrapperClass>();
       for(Note a : listAcct) {
          listWrapper.add(new WrapperClass(a));
List<Contact> listContact = [Select Id, FirstName, LastName,name From Contact where AccountId =: accId order by name DESC];
    if(listContact.size() > 0){
        listWrapper1 = new List<ContactWrapper>();
            for(Contact c : listContact){
                listWrapper1.add(new ContactWrapper(c));

List<Opportunity> listOpp = [select id,name,closeDate from Opportunity where AccountId =: accId order by closeDate ASC];
    if(listOpp.size() > 0){
        listWrapper2 = new List<OpportunityWrapper>();
            for(Opportunity o : listOpp){
                listWrapper2.add(new OpportunityWrapper(o));
public pagereference assignNotes(){
Note no = [select id,title,body,parentId from Note where id=:noteID limit 1];

/*selectedNotes = new List<Note>();
system.debug('*********listWrapper ********'+listWrapper);
for(WrapperClass wrapAccountObj : listWrapper ) {
     if(wrapAccountObj.checkBool == true) {
}  */

selectedContacts = new List<Contact>();
 for(ContactWrapper wrapContactObj : listWrapper1){
     if(wrapContactObj.checkBool == true){
         Note nt = new Note();
         nt.Title = no.title;
         nt.Body = no.body;
         nt.ParentId = wrapContactObj.cons.Id;
insert contactNote;
selectedOpps = new List<Opportunity>();
  for(OpportunityWrapper wrapOppObj : listWrapper2){
      if(wrapOppObj.checkBool == true){
          Note nt = new Note();
          nt.Title = no.title;
          nt.Body = no.Body;
          nt.parentId = wrapOppObj.ops.Id;
         // system.debug('******selectedOpps*********'+selectedOpps);
insert oppNote;
  PageReference pg = new PageReference('/apex/DisplayAccountNotes?id='+accId);  //Redirect on the same page
       return pg; 
public class WrapperClass{
   public Boolean checkBool {get;set;}
   public Note acct {get;set;}
   public WrapperClass(Note acct){
        this.acct = acct;
        checkBool = false;
public class ContactWrapper{
   public Boolean checkBool {get;set;}
   public Contact cons {get;set;}
   public ContactWrapper(Contact cons){
        this.cons = cons;
        checkBool = false;
public Class OpportunityWrapper{
   public Boolean checkBool {get;set;}
   public Opportunity ops {get;set;}
   public OpportunityWrapper(Opportunity ops){
        this.ops = ops;
        checkBool = false;

Test Class-----------------------------------------------------------------------

public class DisplayNotesNewTestClass {

  static testmethod void test1(){

    PageReference pageRef = Page.DisplayAccountNotes;
    Account acc = new Account(name='vivek112');
    insert acc;
    DisplayNotesNew obj = new DisplayNotesNew(new ApexPages.StandardController(acc));
    Contact con = new Contact(FirstName='vivek112', AccountId = acc.Id);
    List<Contact> lstcon = new List<Contact>();
    Opportunity opp = new opportunity(name = 'a',stageName = 'Closed Won',closedate = date.today(),Renewal_Date__c = date.today(),AccountId = acc.Id);
    List<Opportunity> lstopp = new List<Opportunity>();
 	Note note = new Note(parentid = acc.Id,title='test',body= 'hi');
    List<note> nList = new List<Note>();
    boolean RadioValue = true;
    Id noteID = note.Id;
    DisplayNotesNew objCustom = new DisplayNotesNew ();
    DisplayNotesNew.ContactWrapper objwrap = new DisplayNotesNew.ContactWrapper(con);
    DisplayNotesNew.OpportunityWrapper objwrap1 = new  DisplayNotesNew.OpportunityWrapper(opp); 
    DisplayNotesNew.WrapperClass objwrap2 = new DisplayNotesNew.WrapperClass(note);
I am getting an error in noteID and it is throwing error 'List has no rows for assignment'.Please help.

Devanshu soodDevanshu sood

List has no rows for assignment

in which line??

Amita TatarAmita Tatar
Class.DisplayNotesNew.assignNotes: line 57, column 1
Class.DisplayNotesNewTestClass.test1: line 37, column 1
Amita TatarAmita Tatar
The query which is fetched from noteid gives this error, because it does not get the noteID
Devanshu soodDevanshu sood
try to insert note
note n=new note(........................);
then use

and let me know if it works
Devanshu soodDevanshu sood

Note note = new Note(parentid = acc.Id,title='test',body= 'hi');


Amita TatarAmita Tatar
Hi Devanshu,

I got noteID, but now i am getting error for line 71 ,listwrapper. How to include the wrapperlist in the test class?