function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
sfdc@isha.ax1814sfdc@isha.ax1814 

urgent..Need test class for apex class?

Hi Iam new to witing test class any body help me out the test class for below class?
public class BadgeAssignmentReportController{ public string un { get; set; } public List<WorkBadge> badges { get; set; } public List<WorkBadge> listbadges{get; set;} public Boolean badgeListSize{get;set;} public boolean noBadgeMsg{get;set;} public String fromDate{get;set;} public String toDate{get;set;} public PageReference generateBadgeReport() { system.debug('-------------------------'+un); system.debug('-----------toDate--------------'+toDate); system.debug('-----------fromDate--------------'+fromDate); Date myfromDate; String[] tempStr = fromDate.split('/'); Integer m = Integer.valueOf(tempStr[0]); Integer d = Integer.valueOf(tempStr[1]); Integer y = Integer.valueOf(tempStr[2]); myfromDate= Date.newInstance(y,m,d); Date mytoDate; String[] tempStr1 = toDate.split('/'); Integer m1 = Integer.valueOf(tempStr1[0]); Integer d1 = Integer.valueOf(tempStr1[1]); Integer y1 = Integer.valueOf(tempStr1[2]); mytoDate = Date.newInstance(y1,m1,d1); system.debug('--------------myFromDate -----------'+myFromDate); system.debug('--------------myFromDate -----------'+mytoDate ); if(un == null || un=='--None--'){ ApexPages.addmessage(new ApexPages.message(ApexPages.severity.WARNING,'Please Select a User')); } if(toDate == null){ ApexPages.addmessage(new ApexPages.message(ApexPages.severity.WARNING,'Please Select To Date')); } if(fromDate ==null){ ApexPages.addmessage(new ApexPages.message(ApexPages.severity.WARNING,'Please Select From Date')); } listbadges = new List<WorkBadge>(); listbadges=[select id,RecipientId,CreatedById,Definition.imageUrl,Definition.Description,CreatedDate from WorkBadge where RecipientId=:un and CreatedDate >=:myFromDate and CreatedDate <=:mytoDate]; // system.assertEquals(listbadges,null); badges =new List<WorkBadge>(); badges.addall(listbadges ); badgeListSize = badges.size()>0? true:false; noBadgeMsg = badges.size()==0? true:false; return null; } public List<selectoption> options=new List<selectoption>(); public List<selectoption> getPickvaluesTest() { //profile userProfile =[select id from profile where name ='Chatter Free User' limit 1]; if(options.size()>0){ options.clear(); } options.add(new selectoption('--None--','--None--')); for(User us:[select id,Name from User where isactive = true]) { options.add(new selectoption(us.id,us.Name)); } return options; }

 Thanks,

 

Isha

Best Answer chosen by Admin (Salesforce Developers) 
Abhi_TripathiAbhi_Tripathi

Hi,

 

Use this, run this test class, then check the coverage, then modify it with your convenience

 

@isTest(seeAllData=false)
    private class Test_BadgeAssignmentReportController { 

        //Method
        static testMethod void BadgeAssignmentReportControllerTest() {

			//Insert WorkBadge
			WorkBadge wb = new WorkBadge(Name = 'test');
			insert wb;

			//Calling controller
			BadgeAssignmentReportController controller = new BadgeAssignmentReportController();

			//Calling method
			pageReference pageRef = controller.generateBadgeReport();


        }
    }

 

All Answers

Abhi_TripathiAbhi_Tripathi

Hi,

 

Go for this post , it will definetly helps you out

 

http://abhithetechknight.blogspot.in/2013/10/salesforce-test-class-basics.html

sfdc@isha.ax1814sfdc@isha.ax1814

hi abhi thanks for your reply

 

I tried but i think some where i missed please send me the detail test class iam very new to coding please help me.

 

Abhi_TripathiAbhi_Tripathi

Hi,

 

Use this, run this test class, then check the coverage, then modify it with your convenience

 

@isTest(seeAllData=false)
    private class Test_BadgeAssignmentReportController { 

        //Method
        static testMethod void BadgeAssignmentReportControllerTest() {

			//Insert WorkBadge
			WorkBadge wb = new WorkBadge(Name = 'test');
			insert wb;

			//Calling controller
			BadgeAssignmentReportController controller = new BadgeAssignmentReportController();

			//Calling method
			pageReference pageRef = controller.generateBadgeReport();


        }
    }

 

This was selected as the best answer