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