Hot answers tagged


If you're dealing with a custom SObject, then that relationship is going to be a custom field. Therefore, it'll be Account__c, and you'll need to use Account__r.Name1 in your query. That'll be true for both lookup relationships and master-detail relationships. The only time you can avoid using __c or __r is when you're dealing with a standard relationship (e....


You can just check for field existence before query. Boolean fieldExists = Id.valueOf(recordID).getSobjectType().getDescribe().fields.getMap().containsKey('YOUR_FIELD_API_NAME'); String queryStr = 'SELECT Id' + (fieldExists ? ', YOUR_FIELD_API_NAME ' : '') + ' FROM ' + objkey + ' WHERE id = :recordID';

Only top voted, non community-wiki answers of a minimum length are eligible