+ Start a Discussion
Jeffrey ZhangJeffrey Zhang 

tips on managing long soql queries

Was wondering if there is any good sample code for java on how to split up queries with giant 'where' section, because I ended up hitting the 20,000 character limit error.

 stateMessage='ClientInputError : Failed to read query. Exceeded max size limit of 20000 with response size 20001'

it depends. Either you are hitting the limit because of the "where" part of your query (such as where id in ('xxxx','yyyy',.....'zzzz'). In this situation run multiple queries, splitting by yourself your list used in your "where" clause.
Or it is because you have to many fields on your object and querying them all. The best practice is to have short api names. Try renaming them if you can. Try to remove unnecessary fields from your query too. For instance if it is for a backup and you have formula fields refering to other fields of your record, it is not necessary to have this field in your query as you can reconstruct that data with other fields.
Try to minify your query too, removing unnecessary space, carriage returns, tabs...