6

I am very very new to Salesforce. I inherited a project which is using the SOAP API and PHP. There are some queries already written but I need to edit them.

One of the queries is:

SELECT
      ID, Name, of_Members_Registered__c, of_Members_that_Attended__c, Event_Date__c,Venue_Name_Lookup__c
    FROM
      Events__c
WHERE ID = 'XXX'

Now, I downloaded the force.com IDE, when I look at the Events__c table, I don't see all those fields. When I go to create -> object in the Salesforce Setup panel, I don't see those other fields.

I understand those are custom fields, but how do I know which custom fields I can access through the query where the FROM is Events__c, is there anywhere where I can see that? I hope my question is clear. Thanks!

3 Answers 3

10

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

0
3

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

2
  • THAT'S exactly what I needed. Wish I could give more upvotes! Mar 5, 2019 at 3:44
  • 2
    one other thing, the 'strip off the last comma' doesn't work since it actually ends with a comma and a space. I changed those 3 lines to query = query.removeEnd(', '); Mar 5, 2019 at 3:53
3

Extending mattandneil'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.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .