Saturday 12 March 2016

Dynamic Query | Select All Field in SOQL | Select * Form Account


Dynamic Select * Form Account Query in salesforce


public Void GetAllField()
{
String query ='';
String SobjectApiName = 'Account';
Map<String, Schema.SObjectType> schemaMap = Schema.getGlobalDescribe();
Map<String, Schema.SObjectField> fieldMap = schemaMap.get(SobjectApiName).getDescribe().fields.getMap();

String strFields = '';

for(String fieldName : fieldMap.keyset() )
{
if(strFields == null || strFields == '')
{
strFields = fieldName;
}else{
strFields = strFields + ' , ' + fieldName;
}
}

query = 'select ' +
strFields + ' from ' + SobjectApiName + ' Limit 10 ';

List <Account> accList = Database.query(query);

}


Thanks ,
Amit Chaudhary

No comments:

Post a Comment