function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion

Looping over fields from a SOQL result

I'm attempting to write a generic field check that our users can easily update for merging with conga docs. 

I have a custom object that maps fields that are required for the docs to properly complete. I then create a sql query from those results and run it against the appropriate oject:



Map<id,Conga_Merge_Fields__c> reqFields = new Map<id,Conga_Merge_Fields__c>([select ID,field_name__c,object_name__c,deal_type__c from Conga_Merge_Fields__c where Object_Name__c = 'Property']);



Map<id,Merge_Fields__c> reqFields = new Map<id,Merge_Fields__c>([select ID,field_name__c,object_name__c from Merge_Fields__c where Object_Name__c = 'Property']);
for (Conga_Merge_Fields__c field : reqFields.values() )
query = query+field.Field_Name__c;
query = query+' from Property__c where id = \''+currentOpportunity.Property__c+'\'';
Property__c prop = Database.query(query);

I then query the DB with the query string and get the fields/values that are required.


I'm stuck on how i can loop over each returned field to check if it's null/blank/0. Is there any way to do this?  I need to know which field failed to properly direct the users on what needs to be fixed.


you can do this in one step:



for( Property_c prop : Database.query(query)){

   <<your code goes here>>