+ Start a Discussion
ShaTShaT 

Query is either selecting too many fields or the filter conditions are too complicated.

Hi, 

I m creating a Query and  selecting multiple columns and summing them it gives me error in test class.

 

|System.UnexpectedException: Query is either selecting too many fields or the filter conditions are too complicated.

 

Eg- [SELECT Area__c aId, 
Area__r.Account__c,
sum(9Revenue__c)cRevenue, 
sum(9Yards__c) cYards, 
sum(10Revenue__c)c1Revenue, 
sum(10_Yards__c)c1Yards, 
from abc] 

 

When i run same query in system log it give me perfect answer.

 

Please help!!!!!!

 

Thanks & Regards

Shailu



Best Answer chosen by Admin (Salesforce Developers) 
bob_buzzardbob_buzzard

Right, but is it only when the query is running as part of a test, or does it occur during normal use?

 

You could detect if the query is being executed from within a test using the Test.isRunningTest() method and alter the query appropriately.

 

However, there's a judgement call here as to whether that test adds any value, as you aren't testing the real query.

 

I'd suggest you take this up with support, as they should be able to advise in more detail exactly what the issue is.

All Answers

bob_buzzardbob_buzzard

The only advice I've seen for this error is from the web services api, which suggests:

 

--- snip ---

 

Try reducing the number of formula fields referenced in the query.

 

--- snip ---

 

 

ShaTShaT

Thanks bob for your reply!!!

 

But I need all formula fields for calculation.If Remove them i dont get desired result.Sum of the Fields are later inserted to object fields.

Is there any other way to do this..?

 

Thanks

Shailu

 

 

bob_buzzardbob_buzzard

Given that this is a test class, is there any way that you can reduce the amount of records that are considered when the query is run inside a test?

ShaTShaT

No..This not test class .I m calling a funtion of class for which i creating a test class.

Its just a sample of the query inside the function which is called in test calss.Test class showes me above message and points to line number from where error came. I have mentioned the Query which is giving me error as a example...

 

Thanks

Shailu

bob_buzzardbob_buzzard

Right, but is it only when the query is running as part of a test, or does it occur during normal use?

 

You could detect if the query is being executed from within a test using the Test.isRunningTest() method and alter the query appropriately.

 

However, there's a judgement call here as to whether that test adds any value, as you aren't testing the real query.

 

I'd suggest you take this up with support, as they should be able to advise in more detail exactly what the issue is.

This was selected as the best answer