2012-09-25 17 views

risposta

9

Dall'interno di Apex, è possibile ottenere questo eseguendo il seguente codice Apex snippet. Se la tua tabella/oggetto è denominata MyObject__c, allora questo ti darà un Set dei nomi API di tutti i campi su quell'oggetto a cui hai accesso (questo è importante --- anche come amministratore di sistema, se determinati campi sulla tua tabella/oggetto non sono visibili attraverso il livello di campo di sicurezza a voi, non saranno visualizzati qui):

// 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); 

per finire questo off, e raggiungere SELECT * FROM MYTABLE funzionalità, si avrebbe bisogno di costruire una query SOQL dinamica utilizzando questi campi:

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); 
2

la chiamata API describeSObject restituisce tutti i metadati relativi a un determinato oggetto/tabella inclusi i relativi campi. È disponibile nelle API Apex di REST &.

1

Provare a utilizzare Schema.FieldSet

Schema.DescribeSObjectResult d = Account.sObjectType.getDescribe(); 
Map<String, Schema.FieldSet> FsMap = d.fieldSets.getMap(); 

complete documentation

+0

Come dovrei interrogare questo con SOQL però? – Maverick

+0

Penso che non sia possibile usare solo SOQL ... puoi farlo usando Javascript (o qualsiasi linguaggio di implementazione dell'API), o Apex come ho risposto. –

+0

Puoi vedere la tua stessa domanda e la stessa risposta qui: http://stackoverflow.com/questions/8780413/salesforce-soql-query-to-fetch-all-the-fields-on-the-entity –

-4

hai provato DESC myTable?

Per me funziona bene, è anche nei suggerimenti sottostanti in corsivo. Guarda:

enter image description here

+0

[sf: MALFORMED_QUERY] MALFORMED_QUERY: token imprevisto: DESC –

+0

Interessante. Per me funziona. – Riccardo

Problemi correlati