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
srikanth11srikanth11 

test case help

i have written this code in controller to appent date time 

string parentID ;
string year = String.valueOf(userInputAppointment.Appt_Date__c.year());
string month = String.valueOf(userInputAppointment.Appt_Date__c.month());
string day =  String.valueOf(userInputAppointment.Appt_Date__c.day());
string hour = userInputAppointment.Appt_24_From_Hour__c;
string minute =userInputAppointment.Appt_24_From_Min__c;
string second = '00';
string stringDate = year + '-' + month
 + '-' + day + ' ' + hour + ':' + 
minute + ':' + second;
Datetime startTime= 
   datetime.valueOf(stringDate);
 
test case i have written for it
Appointment__c app1 = new Appointment__c();
       
         app1.account__c=a.id;
         app1.Branch__c=b.id;
         app1.doctor__c=s1.id;
         app1.Appt_AM_PM__c='am';
          app1.Appt_Date__c=date.ValueOf('2011-09-21');
             
        app1.Appt_24_From_Hour__c='11';
        app1.Appt_24_From_Min__c = '60';
         string year = String.valueOf(app1.Appt_Date__c.year());
string month = String.valueOf(app1.Appt_Date__c.month());
string day =  String.valueOf(app1.Appt_Date__c.day());
string hour = app1.Appt_24_From_Hour__c;
string minute =app1.Appt_24_From_Min__c;
string second = '01';
string stringDate = year + '-' + month
 + '-' + day + ' ' + hour + ':' + minute + ':' + second;


Datetime startTime= 
   datetime.valueOf(stringDate);
but i am getting this error 
System.TypeException: Invalid date/time: 2011-9-21 11:null:00
plz help me how to cover the test case for the date part in the controller

 

 

Rajesh_SFGRajesh_SFG
app1.Appt_Date__c=date.ValueOf('2011-09-21');

  try this instead of above,

   app1.Appt_Date__c = System.today();

srikanth11srikanth11

thanks for the reply but i am gettin the same error any more suggestions my dear friend

nylonnylon

Though I don't understand what you are exactly doing, why do you need to put '60' into minute?

'11:60:01' looks very invalid as time.

srikanth11srikanth11

sorry but  even if i give 30 40 any thing its giving me the same error

nylonnylon

srikanth11, are you sure that the exception comes from the last line of the test code?

what if you try this instead? (just for check)

    Datetime myDate = datetime.valueOf('2011-9-21 11:30:01');