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
RiyajRiyaj 

What date value are I m use?


When I am executing the following apex code.. I cannot get records from table. rather then got following error...

Datetime myDate = dateTime.valueOf('2012-5-23 11:00:00 AM');
List<Attendance__c> attnList=[SELECT id,attendance_Date__c,attendance_Roll__c,class_name__c,Remarks__c,student_Name__c FROM Attendance__c WHERE class_Name__c = 'a0390000002xz12AAA' AND attendance_Date__c= :myDate];
List<Attendance__c> l1 = new List<Attendance__c>();
if(attnList.size()>0)
{
for(Attendance__c c : attnList){
Attendance__c l=new Attendance__c(id=c.id,student_Name__c =c.student_Name__c,attendance_Roll__c=c.attendance_Roll__c,Remarks__c=c.Remarks__c,attendance_Date__c=c.attendance_Date__c);
l1.add(l);
}
}
else
{
Attendance__c l=new Attendance__c();
l1.add(l);
}
return l1;

Debug Area

11:10:26:042 SOQL_EXECUTE_BEGIN [3]|Aggregations:0|select id, attendance_Date__c, attendance_Roll__c, class_name__c, Remarks__c, student_Name__c from Attendance__c where (class_Name__c = 'a0390000002xz12AAA' and attendance_Date__c = :tmpVar1)

|myDate|1337796000000

My table record
----------------------------------------------------------------------------------------------------------------------------------------------------------------
Case Number Class Name Student NameAttendance Roll Attendance Date
----------------------------------------------------------------------------------------------------------------------------------------------------------------
0000000238 NRM-2013-WED-1100-1300-JULIANA Martinus KosasihPresent 5/16/2012 11:00 AM
0000000239NRM-2013-WED-1100-1300-JULIANAMartinusKosasihPresent5/23/2012 11:00 AM


Navatar_DbSupNavatar_DbSup

Hi,

 

You are using the 18 digit id in soql query.

 

List<Attendance__c> attnList=[SELECT id,attendance_Date__c,attendance_Roll__c,class_name__c,Remarks__c,student_Name__c FROM Attendance__c WHERE class_Name__c = 'a0390000002xz12AAA' AND attendance_Date__c= :myDate];

There are two versions of every record Id in salesforce :

• 15 digit case-sensitive version which is referenced in the UI.

• 18 digit case-insensitive version which is referenced through the API.

Instead of using 18 digit id,Use 15 digit id.

 

Did this answer your question? If not, let me know what didn't work, or if so, please mark it solved. 

PaqsPaqs

Instead of using dateTime.valueOf in your code, try with this:

Datetime myDate = datetime.newInstance(2012, 5, 23, 11, 0, 0);

 Cheers