0

The batch is Failing since couple of weeks and throwing error:

First error: [REQUEST_RUNNING_TOO_LONG] Your request was running for too long, and has been stopped

Mostly it seems to happen due to very long query,Any suggestion how it could be resolved?

query-

 select id, BAN__r.Name, BAN__r.BAN_Status__c,
 BAN__r.Status_last_date__c, ClosedDate from case where
 (BAN__r.BAN_Status__c ='C' and BAN__r.Status_last_date__c <
 2015-06-23) or(BAN__c = null and ClosedDate <
 2015-06-23T08:56:45.000Z)or  (RecordTypeID = '01220000000Q2UR' and
 Type = 'Account Administration' and  Case_Sub_Type_1__c = 'Direct
 Debit Request'  and CreatedDate < 2017-04-21T08:56:45.000Z)
1
  • You may want to use the query optimizer in the Developer console to make certain your query is selective. From the looks of it, I somehow don't think it is. Many of those fields aren't indexed and will cause it to need to read each and every row in the table (BAN__c = null for example).
    – crmprogdev
    Sep 13, 2017 at 12:22

1 Answer 1

2

You should seperate your query in two queries.

The first sould query your BAN__c object:

Map<Id, Ban__c> bans = new Map<Id, Ban__c>([SELECT Id FROM Ban__c WHERE BAN_Status__c = 'C' AND Status_last_date__c < 2015-06-23]);

The second would use the results of the first in its first condition:

select id, BAN__r.Name, BAN__r.BAN_Status__c, BAN__r.Status_last_date__c, ClosedDate from case where (BAN__c IN :bans.keySet()) or(BAN__c = null and ClosedDate < 2015-06-23T08:56:45.000Z)or  (RecordTypeID = '01220000000Q2UR' and Type = 'Account Administration' and  Case_Sub_Type_1__c = 'Direct Debit Request'  and CreatedDate < 2017-04-21T08:56:45.000Z)

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .