+ Start a Discussion
ArabindaArabinda 

SOQL Query Taking more time to fetch records with more filter criteria .

Hi Folks,
In sites, I want to display the total count of records based on different conditions.
This will return count more than 4 million records of data. I am using query more api to get the count of records.
It is bypassing the query limit. But this is working fine inside salesforce org.
When I run the same page from sites, it is taking too much of time and resulting 'Down For Manintenance' issue.
Please give a work around to complete the same or to optimize the query. Below shows you the sample query,


Please advice on this.I attached a sample query below.

select count(ID),COUNT_DISTINCT(account.id) from Contact  where (Account.Region__c IN:SelectedRegions )  and (Account.addr_Country__c IN:Selectedcountries)  and  (Account.Primary_Industry_2_digit__c IN:Selected2DigitPrimarySIC )  and  (Account.Primary_Industry_4digit__c IN:Selected4DigitPrimarySIC)  and  (Account.Revenue_Band__c IN:SelectedRevenueBand)  and  (Account.Employee_Band__c IN:SelectedEmployeeBand)  and  (Contact.Department__c IN:SelectedDepartments)  and  (Contact.Job_Function__c IN:SelectedFunctions)  and  (Contact.Seniority_Level__c IN:SelectedReportLevel)


Thanks in Advance
Regards
Arabinda

Sonam_SFDCSonam_SFDC
Hi Arabinda,

Does your Sites.com page have multiple queries like this on the page?
if its taking a lot of time - I would suggest you to break down the query and add individual filters.

Go through the followig cheatsheet for optimization: http://help.salesforce.com/help/pdfs/en/salesforce_query_search_optimization_developer_cheatsheet.pdf