document.write('
Data hosted with ♥ by Pastebin.com - Download Raw - See Original
  1. /*
  2. *  Class Name           : BuildQueryUtil
  3. *  Last Modified Date   : 22-01-2014
  4. *  Created By           : Gautam Singh
  5. *  Class Type           : Utlity
  6. *  Purpose              : Add this excerpt in your utility class to save your queries from
  7. *                           Error: SObject row was retrieved via SOQL without querying the requested field: [field_name]
  8. *                          
  9. */
  10.  
  11. public class BuildQueryUtil{
  12.  
  13.     //constructor
  14.     public BuildQueryUtil(){
  15.        
  16.         //your own utility initialzations
  17.     }
  18.    
  19.     /*
  20.     *
  21.     *  Purpose: Returns the fieldNames comma seperated.
  22.     *  Note: Reason for Not Building Query & sending the field names is: You may want to extract child/parent fields as well!
  23.     *                  
  24.     *
  25.     */
  26.     public static string fieldNames(string objtName){
  27.         string query = \'SELECT\';
  28.         string ObjectName = ObjtName;
  29.        
  30.        
  31.         map<String, Schema.SObjectField> objectFields = Schema.getGlobalDescribe().get(objectName).getDescribe().fields.getMap();
  32.        
  33.         // create the query string by getting field api names from the map.
  34.         for(String s : objectFields.keySet()) {
  35.             query += \' \' + s + \', \';
  36.         }
  37.        
  38.         // remove comma from last, if it exsists
  39.         // if you are planning to add nested query it is recommended that you keep the comma
  40.         if (query.subString(query.Length()-1,query.Length()) == \',\'){
  41.         query = query.subString(0,query.Length()-1);
  42.     query += \' \';
  43.         }
  44.        
  45.         return query;
  46.     }
  47.  
  48. }
');