I have some code that queries some fields from an object. I then use the schema to loop over all of the fields of an object. Is there a way, while I'm looping through the schema to tell if I had queried for a field before I try to use the sobject.get method?
List<Account> accs = [SELECT RecordTypeId, Name FROM Account];
List<Schema.SObjectField> fields = Schema.SOBjectType.Account.fields.getMap().values();
for (Account acc: accs)
{
for (Schema.SObjectField field: fields)
{
//This will fail if I did not query for the field
Object sField = acc.get(field.getDescribe().getName());
}
}