Many of us are on board at plateform from other languages such as JAVA, PHP, .NET etc. Those languages are older then plateform. In those language whn we query the database we use following syntax to get all records.


Salesforce is bit different in that way you can’t directly query this way so this recipe will show you how you can select all fields in SOQL. Try to understand the approach from following code.

// This is the object for which we required data.
Map<String, Schema.SObjectField> objfieldMap = Account.sObjectType.getDescribe().fields.getMap();

String strfieldName = '';

for(Schema.SObjectField Field : objfieldMap.Values())
     Schema.DescribeFieldResult fieldResult = Field.getDescribe();
     strfieldName += fieldResult.getName() + ',';

strfieldName = strfieldName.substring(0, strfieldName.length()-1);
// Build a Dynamic Query String.
List<Opportunity> OppList = Database.query('select ' + strfieldName + ' from Opportunity');

This code use Account.sObjectType.getDescribe().field.getMap() method  to get the sObject data.

It will work the way we have our normal * query in other languages.