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
sandeepathadusandeepathadu 

hi plz help me in my test case

hi all


i have written a controller fulk bulk insertion of records.for the user to input data i have declared userinputappointment in my controller and for the procees to go on i have declared my userinput
field values ti integers where my test case is showing errors plz help me resolve this issue

my controller
public class ExtTwo
{
public ExtTwo(ApexPages.StandardController controller) 
{ 
userInputAppointment = new Appointment__c();
}
public Appointment__c userInputAppointment {get; set;}
public list<appointment__c> apps {get;set;}  
public list<appointment__c> apps1 {get;set;}  
public list<appointment__c> apps2 {get;set;}
public list<appointment__c> apps3 {get;set;}
public list<appointment__c> apps4 {get;set;}
public list<appointment__c> apps5 {get;set;}

public PageReference save()
{
apps = new list<appointment__c>();
apps1 = new list<appointment__c>();
apps2 = new list<appointment__c>();
apps3 = new list<appointment__c>();
apps4 = new list<appointment__c>();
apps5 = new list<appointment__c>();
integer i=integer.valueof(userInputAppointment.from__c);          
integer i1=integer.valueof(userInputAppointment.To__c);
integer i2=integer.valueof(userInputAppointment.from_min__c);
integer i3=integer.valueof(userInputAppointment.To_Min__c);
if(i<i1)
{ 
for(integer k=0;k<(60-i2)/10;k++)
{
appointment__c ap = new appointment__c();
ap.branch__c =  userInputAppointment.branch__c;
ap.account__c = userInputAppointment.Account__c;
ap.doctor__c=userInputAppointment.doctor__c;
ap.appt_date__c = userInputAppointment.appt_date__c;
ap.Appt_AM_PM__c= 'AM';
if(integer.valueof(userInputAppointment.from__c)>=12)
{
ap.Appt_AM_PM__c= 'PM';
}
ap.Appt_Hour__c =String.valueOf(integer.valueof(userInputAppointment.from__c));
if(integer.valueof(userInputAppointment.from__c)>12)
{
ap.Appt_Hour__c =String.valueOf(integer.valueof(userInputAppointment.from__c)-12);
}
ap.Appt_Minute__c = userInputAppointment.from_min__c;
ap.RecordTypeid=userInputAppointment.RecordTypeid;
if(i2!=integer.valueof(userInputAppointment.from_min__c))
{
ap.RecordTypeid='012N0000000CgSu';
}
apps1.add(ap);
}
insert apps1;

my test case

@isTest
private class extwoTestclass
{
static testmethod void TestController() 
{

 
  ApexPages.StandardController con = new ApexPages.StandardController(new Appointment__c()); 
       
      ExtTwo cs = new ExtTwo(con);    
        
      PageReference pr2 = cs.save();
      
     
 } 
          
  }
plzz help me in this
error i am getting
system.null pointer exception.argument 1 cannot be null 
i think the error is in this part as userinputappointment__c is going null plz help me for my test case

integer i=integer.valueof(userInputAppointment.from__c);          
integer i1=integer.valueof(userInputAppointment.To__c);
integer i2=integer.valueof(userInputAppointment.from_min__c);
integer i3=integer.valueof(userInputAppointment.To_Min__c);



 

ANKITAANKITA

HI,

 

Its take more time to get the answer for these kind of questions.

so, Mean while better to approach your immediate Lead to solve your problem.

 

 

Thanks,

Ankita

sandeepathadusandeepathadu

the error of my test case is showing null point exception at this point in my controller

integer i=integer.valueof(userInputAppointment.from__c);   

 

its saying userInputAppointment.from__c is null value . actually this value is entered by user. so for these cases let me know how to write the logic in test casde

Ankit AroraAnkit Arora

If  "userInputAppointment.from_min__c" in below line can be null 

 

if(i2!=integer.valueof(userInputAppointment.from_min__c))

 then you can do something like this :

 

if(userInputAppointment.from_min__c != null)
{
    if(i2!=integer.valueof(userInputAppointment.from_min__c))
    {
         ap.RecordTypeid='012N0000000CgSu';
    }
}

 Let me know if it resolves your problem.

 

 

Thanks

Ankit Arora

Blog | Facebook | Blog Page

sandeepathadusandeepathadu

thanks for the reply ankit ji but i dont have problem with my controller i am not knowing how to write the test case for my controller plz help me in writing the test case for my controller

sandeepathadusandeepathadu

ankit ji plz let me know if u dint get the exact problem i am facing with my test case. plz help me in writing the test case for my controller to cross 75%code coverage

Ankit AroraAnkit Arora

Ok I got it, try this :

 

@isTest
private class extwoTestclass
{
	static testmethod void TestController() 
	{
		//Fill all fields which you are using in the controller
		Appointment__c app = new Appointment__c();
		app.from_min__c = 1 ;
		insert app ;


		ApexPages.StandardController con = new ApexPages.StandardController(app); 
       
	        ExtTwo cs = new ExtTwo(con);    
        
 	        PageReference pr2 = cs.save();
     
	} 
} 

 Please see my comment in code.

 

 

Thanks

Ankit Arora

Blog | Facebook | Blog Page

sandeepathadusandeepathadu

oh ankith ji i filled all the fields as u said but again i am getting the same error system.null pointer exception argument 1 cannot be null ankith ji .the error pointing my controoller at this point

integer i1=integer.valueof(userInputAppointment.To__c);

 

 

 



System.NullPointerException: Argument 1 cannot be nullClass.ExtTwo.save: line 23, column 27 Class.extwoTestclass.TestController: line 31, column 33 External entry point

         

sandeepathadusandeepathadu

ankith ji i want to elobarate on my issue . i have wriiten my controller to bulk insert records for two time slots from and to.The user enters from time and to time and press go and he will get his records in the span of ten minutes. thats my task and so for that i had to initiate userinputa[ppointment in the befggining of myt controller  and wrote the code based on it userinputfrom and userinputto etc etc and these are all null values .so when i write the test case where ever there is userinpuappointment from or to is there there the test case is showing null values so plewase if u get my problem help me with the test case

Ankit AroraAnkit Arora

A bit difficult for me to understand this but now as you getting error in

 

: integer i1=integer.valueof(userInputAppointment.To__c);

 

and not in the previous now that means there is something missing in data. Have you filled To__c value where I told you ?

 

 

Thanks

Ankit Arora

Blog | Facebook | Blog Page

sandeepathadusandeepathadu

i filled it ankith ji and i will let u know if i get the result

Ankit AroraAnkit Arora

Ok! Please make sure you will fill all mandatory values of the object along with atleast which I can see from your code :

 

To_Min__c

from__c

To__c

from_min__c

 

 

Thanks

Ankit Arora

Blog | Facebook | Blog Page