You need to sign in to do that
Don't have an account?
Tony66
SOQL query logic for date condition in Apex controller
On a visual-force page of a workorder record, I've to display list of workorders created for the same location where the createddate is within the last 30 days of the creationdate of the current record.
For ex: If the current record was created on Jan 31st for a location A, I want to display all the workorders that were created from Jan 1st to 31st for location A.
This is the query I've but it obviously displays records created in last 30 days but not the records created in last 30 days of createddate of the current record. How can I modify my query?
For ex: If the current record was created on Jan 31st for a location A, I want to display all the workorders that were created from Jan 1st to 31st for location A.
This is the query I've but it obviously displays records created in last 30 days but not the records created in last 30 days of createddate of the current record. How can I modify my query?
CWOs=[SELECT Id, Status, location.Name, createddate FROM WorkOrder WHERE location.Name = : getwo().location.Name and id != : getwo().id and recordtype.name = 'Child' and createddate = LAST_N_DAYS:30 ORDER BY CreatedDate asc];
You will have to query it twice, firstly you need to query for the createdDate, and get the date variable as:
Date dateVar = workOrderObj.CreatedDate.addDays(-30);
then you can use the query you need to fetch the records for as below:
CWOs=[SELECT Id, Status, location.Name, createddate FROM WorkOrder WHERE location.Name = : getwo().location.Name and id != : getwo().id and recordtype.name = 'Child' and createddate > :dateVar ORDER BY CreatedDate asc];
All Answers
Have you tried choosing the records where the codition is created_date-30 so that only those records are selected which are 30 days from creating date.
Regards,
Anutej
You will have to query it twice, firstly you need to query for the createdDate, and get the date variable as:
Date dateVar = workOrderObj.CreatedDate.addDays(-30);
then you can use the query you need to fetch the records for as below:
CWOs=[SELECT Id, Status, location.Name, createddate FROM WorkOrder WHERE location.Name = : getwo().location.Name and id != : getwo().id and recordtype.name = 'Child' and createddate > :dateVar ORDER BY CreatedDate asc];
May I know on which line?