You need to sign in to do that
Don't have an account?
Help needed to know what query is giving timeout
How can we identify which query is giving us timeout in a Batch Apex processing? We have a Batch Apex that is aborting after N executions. The aborting is caused by timeouts in Oracle Database, and it happens randomly. We cannot see which query is causing it because SFDC doesn't allow you to see it in the UI. We checked them in the Query Plan Tool and none involves tables with more than 150.000 records (low volume). (We have already read about Query Optimizer and High Volumes.)
I already logged a case, but of course they sent me to the forum, even when the only people who can tell me what I need are them.
Sonam, could you help me find the query?, this issue has been burning for some time now, thank you!
I already logged a case, but of course they sent me to the forum, even when the only people who can tell me what I need are them.
Sonam, could you help me find the query?, this issue has been burning for some time now, thank you!
In the Batch "BatchApexPriorizacion" , it's calling a class "PriorizacionesUtil" and the method "armarGrupos" of this class contain a query which is causing timeout.
Query:
for(AggregateResult i : [SELECT Caso__r.AccountID Cuenta, MAFecha_y_Hora__c) FechaHora, Caso__r.Campana__r.Temporada__c Temporada FROM Interaccion__c WHERE Caso__r.AccountID IN :cuentasProcesando GROUP BY Caso__r.AccountID, Caso__r.Campana__r.Temporada__c])
Please otimize this query so it will not give time out issue.
Thanks,
Pratik
All Answers
If you're sure timeout are in Oracle Database, the 1st thing to do is to test these requests connected locally to Oracle.
Also, can you tell us how Salesforce speak to Oracle?
Regards,
Fred
Fred, thanks for your reply. I'm not using oracle on my own, Salesforce.com uses Oracle as database. When you make a query, the Query Optimizer transforms the soql to an oracle's sql query. If that query runs for more than 2 minutes, it gives you a timeout and a message like "Aborted by user".
We need to identify the query (there are several queries in the execute's method) to analize how we can optimize it.
As a suggestion, you can try to add an "order by id" to your query (https://help.salesforce.com/apex/HTViewSolution?id=000171421&language=en_US (https://help.salesforce.com/apex/HTViewSolution?id=000171421&language=en_US)).
Also, you can contact Salesforce Customer Support to create custom indexes if needed.
Hope this helps,
Fred
thanks.
Using developer console, then workspace manager and change Log Levels (I cannot try).
https://www.salesforce.com/us/developer/docs/apexcode/Content/code_setting_debug_log_levels.htm.
Let us know.
Fred
I'll come back if I have more ideas.
Fred
We are adding a custom logging to a document to know what query is the last executed (it's log before the query is executed). I think with that, we could know what query is failing, when it fails.
Any more informations since last time?
Fred
I'll get back to the topic when I get any news.
Regards
In the Batch "BatchApexPriorizacion" , it's calling a class "PriorizacionesUtil" and the method "armarGrupos" of this class contain a query which is causing timeout.
Query:
for(AggregateResult i : [SELECT Caso__r.AccountID Cuenta, MAFecha_y_Hora__c) FechaHora, Caso__r.Campana__r.Temporada__c Temporada FROM Interaccion__c WHERE Caso__r.AccountID IN :cuentasProcesando GROUP BY Caso__r.AccountID, Caso__r.Campana__r.Temporada__c])
Please otimize this query so it will not give time out issue.
Thanks,
Pratik
We are going to work on this query right away, if i have any question I'll post in this thread.
Thanks so much!
Thanks,
Pratik
Query: SELECT Caso__r.AccountID Cuenta, MAX(Fecha_y_Hora__c) FechaHora, Caso__r.Campana__r.Temporada__c Temporada FROM Interaccion__c WHERE Caso__r.AccountID IN :accountIds GROUP BY Caso__r.AccountID, Caso__r.Campana__r.Temporada__c
Result:
The cost showed is from Case's table, but I don't sure if that is the real cost of executing the query over Interaccion__c, I think It's not.
So, I splited the query in two parts, first I query Case's object to get case's ids and then use them over Interaccion__c query:
Step 1 - Query: Select Id From Case Where AccountId IN :accountIds
Result:
Step 2 - Query: SELECT Caso__r.AccountID Cuenta, MAX(Fecha_y_Hora__c) FechaHora, Caso__r.Campana__r.Temporada__c Temporada FROM Interaccion__c WHERE Caso__c IN :caseIds GROUP BY Caso__r.AccountID, Caso__r.Campana__r.Temporada__c
Result:
Do you think this will help to avoid the timeouts that we were experiencing? We already reduced the account's scope from 500 to 200 records in the batch.
Thanks for your help.