You need to sign in to do that
Don't have an account?
Rajan
SOQL query problem
Hi friends,
I have a custome object in which I am saving records and their is a field with name Date_and_Time__c which is containing time and date for next schedule. I need a query which will give all records during current time and next 5 mints. For example if current time is 4:30 PM and I have given time 4:32 PM in Date_and_Time__c field then it should return this record and if their is any other records during this interval then it sould give all records.
My code is as below:
*****************
global static string GetReminder(){
DateTime dt = datetime.now();
DateTime dtIST = dt.addMinutes(330); //330 is GMT +5:30 as IST conversion
//String CurrentdateTime = dt.format('yyyy-MM-dd\'T\'hh:mm:ss\'Z\'');
DateTime dt1 = dtIST.addMinutes(5); // 5 minutes after current time.
List<SetReminder__c> reminderList = [Select Id, Name, Date_and_Time__c, Next_Best_Action__c, Recom_External_Id__c, Recommendation__c from SetReminder__c where (Date_and_Time__c >=: dtIST and Date_and_Time__c <=:dt1)];
system.debug('DT:' + dtIST);
system.debug('DT1:' +dt1);
system.debug('ReminderList:' +reminderList);
return null;
}
Thanks in advance
Regards:
Rajan
I have a custome object in which I am saving records and their is a field with name Date_and_Time__c which is containing time and date for next schedule. I need a query which will give all records during current time and next 5 mints. For example if current time is 4:30 PM and I have given time 4:32 PM in Date_and_Time__c field then it should return this record and if their is any other records during this interval then it sould give all records.
My code is as below:
*****************
global static string GetReminder(){
DateTime dt = datetime.now();
DateTime dtIST = dt.addMinutes(330); //330 is GMT +5:30 as IST conversion
//String CurrentdateTime = dt.format('yyyy-MM-dd\'T\'hh:mm:ss\'Z\'');
DateTime dt1 = dtIST.addMinutes(5); // 5 minutes after current time.
List<SetReminder__c> reminderList = [Select Id, Name, Date_and_Time__c, Next_Best_Action__c, Recom_External_Id__c, Recommendation__c from SetReminder__c where (Date_and_Time__c >=: dtIST and Date_and_Time__c <=:dt1)];
system.debug('DT:' + dtIST);
system.debug('DT1:' +dt1);
system.debug('ReminderList:' +reminderList);
return null;
}
Thanks in advance
Regards:
Rajan
Change line 2 to: And then remove line 4 (strDate = strDate.replace...)
All Answers
I tried but its not returning any record for this interval and I have updating date and time in records as per this interval only. Any idean for this?
I want records between varriable 'dtIST ' and 'dt1'.
May be it is related to the conversion issue. You can find more details in the link given below:
https://nextgensalesforce.wordpress.com/2015/11/30/dynamic-soql-query-results-in-local-time/ (http://https://nextgensalesforce.wordpress.com/2015/11/30/dynamic-soql-query-results-in-local-time/)
Thanks,
Abhishek Bansal.
I am doing the same but not returning any record. Is their any problem with Org Time or time format. My Org time is ''GMT +5:30(IST)'' and time format is in AM and PM format but salesforce is returning in 24 hours format after debuging and once I m saving record then it is saving value in the field is ''9/20/2017 5:40 AM''.
My code is
**********
DateTime dt = datetime.now();
String CurrentdateTime = dt.format('yyyy-MM-dd\'T\'hh:mm:ss\'Z\'');
String strdate = CurrentdateTime;
strDate = strDate.replace('\'T\'', ' ').replace('\'Z\'', '');
datetime dtv = datetime.valueOf(strDate);
Change line 2 to: And then remove line 4 (strDate = strDate.replace...)
Its working fine now.
I have one more requirement. Could you pls help me out for that?
I have designed a custom button for sending email. I have a custom table where I'm displaying data. Whenever I'll select any record using checkbox and click that button then that particular record should go as email with that VF template which I'm using. I'm able to send email with that template but records are not coming. I think their is some problem with data mapping with that template. I'm displaying recods in table from 3 different custom objects with Account and contact standard object. Any idea or do I need to share code with you?
I have sent you the code. Please check and suggest me or do required changes. It will be great help for me. Thanks in advance.