+ Start a Discussion
j_paqj_paq 

Intermittent Query_Timeout error

I've been reading through messages, and I haven't seen this question asked yet.
 
We've been running 2 S-Controls for a couple years now without issue. The control grabs the ID of the current account and then retrieves the related row from a custom object using that ID.  Lately, I have users complaining that the query is timing out. 
 
Strange thing is, I can't replicate the timeout on my machine.  I've seen it happen on their machines, but if I get a call about the timeout I immediately go in and try the same account without error. 
 
Am I just that lucky?    Any ideas as to what's going on?
werewolfwerewolf
Well, it probably has to do with the amount of data the query is sifting through.  Does the object that you're querying have a lot more rows in it than it used to?  Is there a custom index that you might be able to apply to the criteria columns that might make your query run faster?
j_paqj_paq
Thanks for the reply werewolf.
 
The custom object is no larger than it's ever been, and no more rows. 
As for a custom index...could you elaborate?  It's linked directly to the Account object using the Account.Id, one record per account. 
 
But you did give me something to think about. The custom object is all sales-related. To get the data available on the Account object for View creation, we created formulas on the custom object and then used roll-up fields on Account to display.  The S-Control doesn't reference the formulas, but maybe that is causing more overhead on the custom object?  With the new formula options, maybe I should just re-create the roll-ups using the custom formulas.
werewolfwerewolf
Well, a query could time out if it's searching over a large set of data, or if it has some complex query criteria like LIKE '%something%' -- usually it's both actually.  If these rollups aren't part of the query then they probably aren't involved in the problem in any way.

Can you post the query itself here?
PannarPannar

Werewolf,

I am suffering from this Query_Timeout exception for such a long time. I hope you will give some solution how to handle this exception.

here is my query which you asked:-

Code:
Select c.AccountId, c.Account.Id, c.Account.Name, 
c.Account.acc_Id__c, c.Account.tfcmCustomerMasterId__c, 
c.Account.tocCMAddressId__c, c.DoNotCall, c.Email, 
c.FirstName, c.HasOptedOutOfEmail, c.Id, c.LastName, 
c.MailingCity, c.MailingCountry, c.MailingPostalCode, 
c.MailingState, c.MailingStreet, c.MobilePhone, c.Name, 
c.OwnerId, c.Owner.Email, c.Owner.EmployeeNumber, 
c.Owner.FirstName, c.Owner.Id, c.Owner.LastName, 
c.Owner.Name, c.Phone, c.tfContactCategory__c, c.Title, 
c.tocContactStatus__c, c.tocContactId__c,c.Salutation, 
c.tocAssetFocus__c, c.tocDirectMarketing__c, 
c.tocEndUserActivity__c, c.tocFloor__c, 
c.tocFunction__c, c.Department, c.tocLanguage__c, 
c.tocLegalConsent__c, c.tocLocalCity__c, c.tocLocalCountry__c, 
c.tocLocalFirstName__c, c.tocLocalLastName__c, 
c.tocLocalPostal__c, c.tocLocalSalutation__c, c.tocLocalState__c, 
c.tocLocalStreet__c, c.CreatedById, c.CreatedDate, 
c.LastModifiedById, c.LastModifiedDate from Contact c 
where c.tocContactId__c<>null and(c.LastModifiedById <>'User1' or c.CreatedById ='User2')    


 
Could you guide me how to handle this exception thru java code. I couldn't get any complete info from apex api document abt this exception.

I am using the following method to query the sfdc object

 

Code:
qr = sfdcCtrl.query(qry);                
----
if(qr.getDone() ==false)
                {
                    qr = sfdcCtrl.queryMore(qr.getQueryLocator());
                } else {
                    done = true;
                }


 please give me some solution

 

werewolfwerewolf
As I said in an earlier post, it most likely has to do with the number of rows you're sifting through, and your query criteria are not very selective -- can you perhaps add any more selective criteria?  Alternately, you might explore adding a custom index to this tocContactId column, or making it an external key if it's not a pointer to a contact in Salesforce.com.
PannarPannar

Thanks werewolf, the code issue is fixed. i didn't set the batch size via program. the query was always returns the entire records at a single shot intead of returning a specified batch size of 200 records, thats why Querymore function never called and failed to keep the sfdc status as Keep Alive and it got timed out.

I believe after set the batch size as 250, the timeout wouldn't come up again