How to know all fields for a query?

Couple of easy ways to get your head around all the accessible fields:

  • as you did, go to Setup > Create > Objects > Event and scroll to Custom Fields & Relationships,

  • use Workbench then Jump to Standard and Custom Objects > Event__c > Fields

    enter image description here

  • or use Developer Console then File > Open > Objects > Event__c

    developer console


Extending bigassforce's answer with a forth option. You could also describe an object from the CLI using the schema:sobject:describe command, e.g.

sfdx force:schema:sobject:describe -s Account

Or, to export it to a JSON file for closer inspection:

sfdx force:schema:sobject:describe -s Account sobject-describe-Account.json

Find more answer from its CLI Command Reference page.


Extending @bugassforce and @yclian:

You can use this code and Executing Anonymous Apex Code : (https://help.salesforce.com/articleView?id=code_dev_console_execute_anonymous.htm&type=5)

String objectName = 'Events__c';
String query = 'SELECT';
Map<String, Schema.SObjectField> objectFields = Schema.getGlobalDescribe().get(objectName).getDescribe().fields.getMap();

// Grab the fields from the describe method and append them to the queryString one by one.
for(String s : objectFields.keySet()) {
   query += ' ' + s + ', ';
}


// Strip off the last comma if it exists.
if (query.subString(query.Length()-1,query.Length()) == ','){
    query = query.subString(0,query.Length()-1);
}

// Add FROM statement
query += ' FROM ' + objectName;
system.debug(query);

after that check out the log and filter by Debug Only (https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_debugging_system_log_console.htm)

Example from account: enter image description here Code reference: https://gist.github.com/johncasimiro/734428

Tags:

Soql

Query