the only other way to do this besides a
catch is to write your query dynamically so that you get every field.
string queryString = 'SELECT ';
queryString += field+',';
queryString = queryString.removeEnd(',') + ' FROM Account';
if(stillNeedsToAddToQuery) // add WHERE, LIMIT, etc. stuff if need be
list<Account> accountList = (list<Account>)database.query(queryString);
// database.query() returns list<sObject>, so I like to cast my result
See my answer here for some
Utility Methods +
Test Code: Can a SOQL query selecting all columns be generated at runtime?
Both @dphil and my answers are equivalent but opposite in a sense when you are dealing with "general" query results:
- You either filter the input fields for the query (My method gives you all of the fields, and then you can create another method to filter for the appropriate situation.)
catch whatever the "general" query result is. (And there are clever things that can be done in the
catch part too such as break the loop, write another query adding the missing field, and try again with the re-queried results.)