You need to sign in to do that
Don't have an account?
solarcooker
SOQL in schedulable class give no row but Developper Consol return good results
Hi there,
I have a problem with my schedulable class for many days. I create a job with this schedulable class to get date field of a custom object and update them, see the code bellow:
Can somebody explain me what the problem is?
Any kind of help will be welcome.
Cheers
I have a problem with my schedulable class for many days. I create a job with this schedulable class to get date field of a custom object and update them, see the code bellow:
global class SellStovesAtResellerJob implements Schedulable { global void execute(SchedulableContext sc) { //Get the number of days after which stoves delivered to a reseller are sold Integer daysUntilSold = Sales_Settings__c.getInstance('Days_Until_Sold').Number_of_Days__c.intValue(); //Calculate the date of the delivery Date deliveryDate = System.today() - daysUntilSold; //Search for all sales to reseller that have made X days ago and before List<Sale__c> salesToUpdate = [SELECT Date_of_Delivery__c, Date_of_Sale__c FROM Sale__c WHERE Date_of_Delivery__c <= :deliveryDate AND Date_of_Sale__c = null]; //Change the date of sale for (Sale__c sale : salesToUpdate) sale.Date_of_Sale__c = sale.Date_of_Delivery__c + daysUntilSold; //Update the sales update salesToUpdate; } }The main problem is that the query returns no row when I look at the log (I create a trace flag for this class) when the job is finished (with success status) while it gives thousand rows in developper consol. I use the code bellow in an Execute Anonymous Windows:
Integer daysUntilSold = Sales_Settings__c.getInstance('Days_Until_Sold').Number_of_Days__c.intValue(); //Calculate the date of the delivery Date deliveryDate = System.today() - daysUntilSold; //Search for all sales to reseller that have made X days ago and before List<Sale__c> salesToUpdate = [SELECT Date_of_Delivery__c, Date_of_Sale__c FROM Sale__c WHERE Date_of_Delivery__c <= :deliveryDate AND Date_of_Sale__c = null];My user's profil is "System Administrator" with all rights (classes, custom objects and theirs fields, etc ...)
Can somebody explain me what the problem is?
Any kind of help will be welcome.
Cheers
I found a solution but I don't understand the real problem.
As you can see in the first post, there is no LIMIT clause in the SOQL query and this occurs DML limit or CPU limit exception sometimes. Then I limit result to 10 000 but the SOQL query returns no row (logs in second post). Finally I tried to reduce result to 200 and then 1 000, it worked fine for both.
An improvement using a batch will be the best way but this solution can be used for now.
I don't yet understand why the query didn't return anything and it'll good if someone can give explanation about that.
Cheers.
All Answers
Thanks for your quick response.
Please see bellow a part of the log from the scheduled jobs (in Debug Log) and log from Developper Consol: Threre is a little difference with the SOQL query that I give in the first post (ORDER and LIMIT clause) but this is not a problem.
(I can give all rows of the logs if necessary).
Thanks in advance for your help.
I found a solution but I don't understand the real problem.
As you can see in the first post, there is no LIMIT clause in the SOQL query and this occurs DML limit or CPU limit exception sometimes. Then I limit result to 10 000 but the SOQL query returns no row (logs in second post). Finally I tried to reduce result to 200 and then 1 000, it worked fine for both.
An improvement using a batch will be the best way but this solution can be used for now.
I don't yet understand why the query didn't return anything and it'll good if someone can give explanation about that.
Cheers.