SHARE
TWEET

Untitled

a guest Aug 24th, 2019 206 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //prints a SOQL query for all fields of an object, paste into the SOQL editor in webstorm to get a feeling for an object type in the database
  2. String type='spo4__SalesProcess__c';
  3.  
  4. Map<String, Schema.SObjectType> schemaMap = Schema.getGlobalDescribe();
  5. Schema.SObjectType leadSchema = schemaMap.get(type);
  6. Map<String, Schema.SObjectField> fieldMap = leadSchema.getDescribe().fields.getMap();
  7. List<String> fieldList = new List<String>();
  8. for (String fieldName: fieldMap.keySet()) {
  9.   fieldList.add(fieldName);
  10. }
  11. String SOQLString = '\n\nSELECT ' + string.join(fieldList,', ');
  12. SOQLString += ' FROM ' + type + ' LIMIT 10\n';
  13. System.debug(SOQLString);
  14.  
  15.  
  16.  
  17. //prints "##Field API Name: {API Name} => {Label Name}" for all fields on an object
  18. String type='OpportunityStage';
  19. Map<String, Schema.SObjectType> schemaMap = Schema.getGlobalDescribe();
  20. Schema.SObjectType leadSchema = schemaMap.get(type);
  21. Map<String, Schema.SObjectField> fieldMap = leadSchema.getDescribe().fields.getMap();
  22. for (String fieldName: fieldMap.keySet()) {
  23.   System.debug('##Field API Name: ' + fieldName + ' => ' + fieldMap.get(fieldName).getDescribe().getLabel());
  24. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top