You need to sign in to do that
Don't have an account?

Question about soql
How can i reach the last record in the for loop as following:
for (Timesheet__c timeSheet: [select Total_Hours__c, Hours__c from Timesheet__c])
I want to do some operation in the last timesheet. Thanks in advance for any help.
consider :
Timesheet__c ts;
try {
ts = [select Total_Hours__c, Hours__c from Timesheet__c ORDER by createddate desc LIMIT 1][0]
}
catch (exception ex) { //throw no Timesheet}
i ordered by createddate,you may want to do another date..
All Answers
consider :
Timesheet__c ts;
try {
ts = [select Total_Hours__c, Hours__c from Timesheet__c ORDER by createddate desc LIMIT 1][0]
}
catch (exception ex) { //throw no Timesheet}
i ordered by createddate,you may want to do another date..