Here is the way to query the all field’s values without mentioning the Field name.
- // Specify the Object Name to retrieve the List of field names.
- Map<String, Schema.SObjectField> fieldMap = Account.sObjectType.getDescribe().fields.getMap();
- String fieldName = '';
- String accountQuery;
- for(Schema.SObjectField currentField : fieldMap.Values())
- {
- Schema.DescribeFieldResult fieldResult = currentField.getDescribe();
- fieldName += fieldResult.getName() + ',';
- }
- fieldName = fieldName.substring(0, fieldName.length()-1);
- // Build a Dynamic Query String.
- accountQuery = 'SELECT ' + fieldName + ' FROM Account';
- List<Account> accList = Database.query(accountQuery);
Reference:
No comments:
Post a Comment