You need to sign in to do that
Don't have an account?
My Apex Get Date Value is not working???
Hi.
In my webapplication i wanna to bind the data's from salesforce to Grid View. When binding data should follow the one condition. that mean data have one date field, that date field binded in drop down list in Asp.Net page. User click which date data'a to want to display i grid... So When I reterive the date is not match into Apex Date..
Can Any one solve the Problem?
APEX CODE
global class getAttendanceGrid{
WebService static List<Attendance__c> getAttendanceForGrid(string classname,String dateString){
DateTime dtAttendance= datetime.valueof(dateString);
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 = :classname AND attendance_Date__c= :dtAttendance];
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);
}
}
return l1;
}}
ASPX CODE
DateSelect = '5/23/2012 6:00:00 PM';
getAttendanceGrid.Attendance__c[] getAttendanceGridResponse = getAttendanceGridObj.getAttendanceForGrid(sClassID, DateSelect);
above dateselect is the user select date, but it does not match the apex code, but it return the error.......
how do i convert date format ??
Hi,
You have to create a method which will convert that string into desired format. Try the below code as reference:
1st:
public DateTime getConvertDateTime(string strDT)
{
Map<string,integer> MapMonthList = new Map<string,integer>();
MapMonthList.put('January',1);
MapMonthList.put('February',2);
MapMonthList.put('March',3);
MapMonthList.put('April',4);
MapMonthList.put('May',5);
MapMonthList.put('June',6);
MapMonthList.put('July',7);
MapMonthList.put('August',8);
MapMonthList.put('September',9);
MapMonthList.put('October',10);
MapMonthList.put('November',11);
MapMonthList.put('December',12);
String[] strDTDivided = strDT.split(' ');
string month = String.ValueOf(MapMonthList.get(strDTDivided.get(0)));
string day = strDTDivided.get(1).replace(',', '');
string year = strDTDivided.get(2);
string hour = strDTDivided.get(3).split(':').get(0);
string minute = strDTDivided.get(3).split(':').get(1);
string second = '00';
if (strDTDivided.get(4) == 'PM')
{
hour = String.ValueOf(Integer.ValueOf(hour) + 12);
}
string stringDate = year + '-' + month + '-' + day + ' ' + hour + ':' + minute + ':' + second;
return datetime.valueOf(stringDate);
}
2nd:
string mappedDueDate = '17/11/2011';
DateTime taskActivityDate=DateTime.newInstance(Integer.valueOf(mappedDueDate.substring(6,10)), Integer.valueOf(mappedDueDate.substring(4, 5)), Integer.valueOf(mappedDueDate.substring(1,2)), 0, 0, 0);
system.debug('@@@@@@@@@@@' +taskActivityDate);
Did this answer your question? If not, let me know what didn't work, or if so, please mark it solved.