+ Start a Discussion
Waqas AliWaqas Ali 

Get all the records within the last 24-hour according to LastModifiedDate

I want to get all the records within the last 24-hour according to LastModifiedDate , Here is what I am doing

global class SalesOrderSchedule implements Schedulable
{
    global static String CRON_EXP = '0 0 0   ? *'; 

    global void execute(SchedulableContext sc)
    {
        doOpportunityUpdates();
    }

    global void doOpportunityUpdates()
    {
        List<Opportunity> opps = new List<Opportunity>();
        DateTime dt_lastDay = System.now()-1;
        DateTime dt_currentDay = System.now();
        for(Sales_Order__c salesorder : [select id, Name, LastModifiedDate from Sales_Order__c WHERE LastModifiedDate  > = :dt_lastDay AND LastModifiedDate < :dt_currentDay ] )
        {
         //my functionality    
    }
}
but this query is not working, Guys help
Abhishek BansalAbhishek Bansal
Hi Waqas,

Please change your code with the below code:
global class SalesOrderSchedule implements Schedulable
{
    global static String CRON_EXP = '0 0 0   ? *'; 

    global void execute(SchedulableContext sc)
    {
        doOpportunityUpdates();
    }

    global void doOpportunityUpdates()
    {
        List<Opportunity> opps = new List<Opportunity>();
        DateTime dt_lastDay = System.now().addHours(-24);
        DateTime dt_currentDay = System.now();
        for(Sales_Order__c salesorder : [select id, Name, LastModifiedDate from Sales_Order__c WHERE LastModifiedDate  > = :dt_lastDay AND LastModifiedDate < :dt_currentDay ] )
        {
         //my functionality    
    }
}
Let me know if there is any issue.

Thanks,
Abhishek