You need to sign in to do that
Don't have an account?
Amita 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.
-Amita
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'); system.debug('********************'+accId); 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(){ system.debug('******noteID******'+noteID); Note no = [select id,title,body,parentId from Note where id=:noteID limit 1]; system.debug('********no******'+no); /*selectedNotes = new List<Note>(); system.debug('*********listWrapper ********'+listWrapper); for(WrapperClass wrapAccountObj : listWrapper ) { if(wrapAccountObj.checkBool == true) { selectedNotes.add(wrapAccountObj.acct); system.debug('*********selectedNotes********'+selectedNotes); } } */ 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; contactNote.add(nt); //selectedContacts.add(wrapContactObj.cons); //system.debug('*********selectedContacts******'+selectedContacts); } } 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; oppNote.add(nt); //selectedOpps.add(wrapOppObj.ops); // system.debug('******selectedOpps*********'+selectedOpps); } } insert oppNote; PageReference pg = new PageReference('/apex/DisplayAccountNotes?id='+accId); //Redirect on the same page pg.setRedirect(true); 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----------------------------------------------------------------------- @isTest public class DisplayNotesNewTestClass { static testmethod void test1(){ PageReference pageRef = Page.DisplayAccountNotes; Test.setCurrentPage(pageRef); Account acc = new Account(name='vivek112'); insert acc; DisplayNotesNew obj = new DisplayNotesNew(new ApexPages.StandardController(acc)); ApexPages.CurrentPage().getparameters().put('id',acc.id); Contact con = new Contact(FirstName='vivek112', AccountId = acc.Id); List<Contact> lstcon = new List<Contact>(); lstcon.add(con); 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>(); lstopp.add(opp); system.debug('lstopp'+lstopp); Note note = new Note(parentid = acc.Id,title='test',body= 'hi'); List<note> nList = new List<Note>(); nList.add(note); boolean RadioValue = true; Id noteID = note.Id; system.debug('noteID--------'+noteID); 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); objCustom.assignNoteId(); objCustom.assignNotes(); } }I am getting an error in noteID and it is throwing error 'List has no rows for assignment'.Please help.
-Amita
List has no rows for assignment
in which line??
Class.DisplayNotesNewTestClass.test1: line 37, column 1
note n=new note(........................);
then use
ApexPages.CurrentPage().getparameters().put('note',n.id);
and let me know if it works
Note note = new Note(parentid = acc.Id,title='test',body= 'hi');
ApexPages.CurrentPage().getparameters().put('note',note.id);
I got noteID, but now i am getting error for line 71 ,listwrapper. How to include the wrapperlist in the test class?