Tuesday, December 6, 2016

Apex code to Select All Fields in SOQL.


Apex Code To get The All the fields in the Object.

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;

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

}

No comments:

Post a Comment