When running a dynamic query with certain formula fields I get the following error:
System.UnexpectedException: Query is either selecting too many fields or the filter conditions are too complicated.
This usually happens if the end user includes certain formula fields in thequery that are expanded into particularly large SQL statements when they are evaluated in the query.
Is there any good way to see when you are close to this limit based on the field describe information and then split/truncate your query appropriately?
SELECT fieldlist from myCustomObject__c where WHERE Id IN :aRecordIds
Agree with subodhbahl, your hitting an Oracle limit, but it’s more complicated than just SQL expressions based on formula fields.
The only known work-around is to reduce the complexity of your query. Limit the number of fields, formula fields, large text area fields (limit size helps), reduce roll up summary fields in your query, and limit your filters if possible.
I’ve raised this issue with Salesforce support in the past, and I was told Salesforce doesn’t have a formula for calculating when a SOQL query is too complicated. We are flying blind. Suggest adding a configurable setting to help throttle the number of fields you are querying.
Also note: Once you start hitting issues like this, you may find issues with mobile lite as last I remember…the fields queried cannot be configured by administrators. Again, no indicator that your about to outgrow your free licenses of mobile lite, it’s based on when your queries become complex.
Hope these comments help.