Salesforce SOQL描述表

Salesforce SOQL描述表,salesforce,soql,Salesforce,Soql,是否有方法获取Salesforce表中所有字段的列表?描述myTable不工作,并从myTable不工作中选择* describeSObject API调用返回关于给定对象/表(包括其字段)的所有元数据。它在SOAP、REST和Apex API中可用。尝试使用Schema.FieldSet 在Apex中,您可以通过运行以下Apex代码片段来实现这一点。如果您的表/对象名为MyObject__c,则这将为您提供该对象上您有权访问的所有字段的一组API名称。即使是作为系统管理员,这一点也很重要。如果

是否有方法获取Salesforce表中所有字段的列表?描述myTable不工作,并从myTable不工作中选择*

describeSObject API调用返回关于给定对象/表(包括其字段)的所有元数据。它在SOAP、REST和Apex API中可用。

尝试使用Schema.FieldSet


在Apex中,您可以通过运行以下Apex代码片段来实现这一点。如果您的表/对象名为MyObject__c,则这将为您提供该对象上您有权访问的所有字段的一组API名称。即使是作为系统管理员,这一点也很重要。如果您的表/对象上的某些字段无法通过字段级安全性看到,它们将不会显示在此处:

// Get a map of all fields available to you on the MyObject__c table/object
// keyed by the API name of each field
Map<String,Schema.SObjectField> myObjectFields 
   = MyObject__c.SObjectType.getDescribe().fields.getMap();

// Get a Set of the field names
Set<String> myObjectFieldAPINames = myObjectFields.keyset();

// Print out the names to the debug log
 String allFields = 'ALL ACCESSIBLE FIELDS on MyObject__c:\n\n';
for (String s : myObjectFieldAPINames) {
    allFields += s + '\n';
}
System.debug(allFields);
你试过描述我的桌子吗

对我来说,它工作得很好,它也在斜体的基本提示中。看:


我如何用SOQL查询这个问题呢?我认为仅仅使用SOQL是不可能的。。。您可以使用Javascript或任何API实现语言,或我回答的Apex来完成此操作。您可以在此处看到相同的问题和相同的答案:[sf:MALFORMED_QUERY]MALFORMED_QUERY:意外标记:DESC
// Get a map of all fields available to you on the MyObject__c table/object
// keyed by the API name of each field
Map<String,Schema.SObjectField> myObjectFields 
   = MyObject__c.SObjectType.getDescribe().fields.getMap();

// Get a Set of the field names
Set<String> myObjectFieldAPINames = myObjectFields.keyset();

// Print out the names to the debug log
 String allFields = 'ALL ACCESSIBLE FIELDS on MyObject__c:\n\n';
for (String s : myObjectFieldAPINames) {
    allFields += s + '\n';
}
System.debug(allFields);
List<String> fieldsList = new List<String>(myObjectFieldAPINames);
String query = 'SELECT ';
// Add in all but the last field, comma-separated
for (Integer i = 0; i < fieldsList.size()-1; i++) {
   query += fieldsList + ',';
}
// Add in the final field
query += fieldsList[fieldsList.size()-1];
// Complete the query
query += ' FROM MyCustomObject__c';
// Perform the query (perform the SELECT *)
List<SObject> results = Database.query(query);