Can I tell if I queried a field?

I just came up with an idea:

try
{
  Object sfield = audit.get(fromName);
} catch (Exception e)
{
  continue;
}

Does anyone have a better idea without catching it if there is an error though?


Use Map<String, Object> getPopulatedFieldsAsMap() method on the sobject. It gives you a map of fields and values that got queried.

Please refer to this release notes for more information: (http://releasenotes.docs.salesforce.com/en-us/summer16/release-notes/rn_apex_sobject_getmap.htm)