You need to sign in to do that
Don't have an account?
shobana shobana
how to write test class for for loop used in wrapper class
Hi everyone,
I am new bie to Salesforce.
This is my first Test class.
I tried but somewhere i did mistake.
anyone give me guidelines to solve this.
I am new bie to Salesforce.
This is my first Test class.
I tried but somewhere i did mistake.
anyone give me guidelines to solve this.
My class public class opentasks { public List<OpenActivity> open{get;set;} public Id leadld{get;set;} public list<wrapperclass> listwrapper{get;set;} public opentasks(ApexPages.StandardController controller){ leadld = ApexPages.CurrentPage().getparameters().get('id'); list<task> open1 =new list<Task>(); listwrapper = new list<wrapperclass>(); list<lead> le =[SELECT Name, (Select Id,Subject, WhoId, ActivityDate,Status, Priority, OwnerId FROM Tasks WHERE IsClosed=false) FROM Lead WHERE Id = :leadld]; if(!le.isEmpty()){ for(Task k: le[0].Tasks) { listwrapper.add(new Wrapperclass(k)); } } } public class wrapperclass { public boolean checked{get;set;} public Task k{get;set;} public Wrapperclass(Task k){ this.k=k; } } public PageReference close() { list<Task> listofopen=new list<Task>(); if(!listwrapper.isEmpty()){ for(Integer i=0; i<listwrapper.size();i++) { wrapperclass w = listwrapper[i]; if(w.checked==true){ system.debug(w); w.k.status='completed'; listofopen.add(w.k); listwrapper.remove(i); i--; } } } if(listofopen.isEmpty()) { ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.ERROR,'Select atleast one column ')); } else{ update listofopen; } My test class: public class c{ static TestMethod void testforlead() { Test.StartTest(); User user =new User(Id=UserInfo.getUserID()); System.runAs(usr){ Lead l1=new Lead(); l1.Text(80)='shobana'; l1.Company='rix'; l1.Status='Working-contacted'; Insert l1; Task t1=new Task(); t1.Owner='shoba shoba'; t1.Subject='cc'; t1.Priority='High'; t1.Status='In progress'; t1.Whoid=l1.Id; Insert t1; ApexPages.StandardController stdcontroller = new ApexPages.Standardcontroller(l1); opentasks cls= new opentasks( stdcontroller); cls.close(); for(wrapperclass w:cls.listwrapper) { w.Checked=true; break; } cls.close(); } Test.stopTest(); } }Thank you in advance.
Try below test class
Regards,
Bhanu Mahesh
All Answers
Try below test class
Regards,
Bhanu Mahesh
Thanks a lot for sending me code.
It's working good....