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 

How do i get Date field original Date when executing in Apex Query....????

Hi

I m using following Apex Class code...

---------------------------------------------------------------------------------------------------------
List<Attendance__c> r=[SELECT Id,attendance_Date__c,attendance_Roll__c,Remarks__c,student_Name__c FROM Attendance__c WHERE classname__c='Learn Corn' AND attendance_Date__c=2012-05-12];
Attendance__c r1;
if(r.size()>0)
{
r1=new Attendance__c(Id=r[0].Id);
return r[0];
}
else
return new Attendance__c();
---------------------------------------------------------------------------------------------------------
My table records
---------------------------------------------------------------------------------------------------------
Id : a0590000002LE9sAAG
ClassName : Learn Corn -- From Look up
Attendance Date : 5/12/2012
Attendance Roll : Present
Remarks : Hello
Student Name : Gio -- From Look up
---------------------------------------------------------------------------------------------------------
but when i debug it is not working, rather than return values are like
---------------------------------------------------------------------------------------------------------
Id : a0590000002LE9sAAG
ClassName : Learn Corn
Attendance Date : 1336780800000
Attendance Roll : Present
Remarks : Hello
Student Name : Gio
Class Name : Learn Corn
---------------------------------------------------------------------------------------------------------
How do i get Date field original Date when executing in Apex Query....????

bob_buzzardbob_buzzard

That looks like the raw form of a date, which is the number of milliseconds from a particular point in time.  When you output a date to the debug log, you can use the .format() method, which returns a string representation in the current user's locale.  E.g

 

System.debug('Attendance date ' + obj.Attendance_Date__c.format());

 

RiyajRiyaj

I got Error

Method does not exist or incorrect signature: obj.Attendance_Date__c.format()

bob_buzzardbob_buzzard

obj needs to be replaced with the name of your sobject.  

RiyajRiyaj

Sorry,

 

 

It is not working..it is not allowed Sytem.Debug.

 

APex Code:

 

List<Attendance__c> lstConts = new List<Attendance__c>();

String dt ='05-12-2012';
DateTime dt1=System.debug(dt + attendance__c.attendance_Date__c.format());
lstConts=[Select student_Name__c,attendance_Roll__c from Attendance__c where class_Name__r.Name= 'Attendance Clan' AND student_Name__r.Name= 'Gio' AND attendance_Date__c = dt1  LIMIT 1];
if(lstConts.size() > 0)
{
Attendance__c conts = new Attendance__c();
conts = lstConts[0];
conts.attendance_Roll__c= 'Present';
update conts;
}

 

bob_buzzardbob_buzzard

You can't use system.debug to generate a datetime in that way - it doesn't return a datetime and you are concatenating two strings.  Also, you are using the sobject type Attendance__c rather than a record instance.

 

I'm confused as to what you are trying to achieve now - you asked about outputting a date and now you seem to be trying to generate a datetime to back a query.

RiyajRiyaj


Hi,

Ok Now I m explain the task breifly..

 

Now I m developing Asp. WEbapplication using salesforce..

 

In sales froce I have object name 'Class' and 'Attendance' . In Attendance have a following fileds
Attendance Date, StudentName, ClassName, Roll.. When I want update the Field Roll wheather using Present/Absent, I need a Attendance record. So I passing parameter passing from aspx page like StudentName, ClassName, and Attendance Date. Here I want to date parameter format correctly... So Is my first question when I am passing the parameter from outside to apex code which date format i am following?

 

Another one when creating the Attendance record from asp.net. i need same above fields. So same I need Date Parameter from c# area..normally the date return '05/12/2011 12:00:00 AM' it is not support the Apex class..

 

 

1. how do I update the Attendance record from using c# parameter?
2.how do i insert the new record from Attendacne record from using c# parameter?

 

Update Apex Class Is


global class UpdateAttendanceList{
WebService static void UpdateAttendanceFromClassname(string id,string classname,string studentname,string attendance){
List<Attendance__c> Alist=[Select student_Name__c,attendance_Roll__c from Attendance__c where id = :id AND class_Name__r.Name= :classname AND student_Name__r.Name= :studentname];
if(Alist.size()>0)
{
Attendance__c conts=Alist.get(0);
conts.attendance_Roll__c= attendance;
update conts;
}

}}


Update Aspx Code:


updateAttendanceObj.UpdateAttendanceFromClassname(Id,sClassName, sStudentname, attendanceText);
//Values
updateAttendanceObj.UpdateAttendanceFromClassname(a0590000002LTetAAG,a0390000002vWW9AAM,0039000000CYPcOAAX,Present);


Insert Apex Class Is

global class InsertOneAttendanceDate{
WebService static void InsertOneDateAttendance(string studentname,string classname,date dtattendance){
Attendance__c i=new Attendance__c(student_Name__c= studentname,class_Name__c= classname,attendance_Date__c= dtattendance);
Insert i;
}
}


Insert Aspx Code:

InsertAttendanceObj.InsertOneDateAttendance(UserId, ClassNameID, firstweekday.Date);

//Values

InsertAttendanceObj.InsertOneDateAttendance(0039000000CYPcOAAX,a0390000002vWW9AAM,05/22/2012 12:00:00 AM)