public class ExtractFields {
public static void queryAllFields(String objTypeName) {
Schema.DescribeSObjectResult[] descResult =
Schema.describeSObjects(new String[]{objTypeName});
Map<String, Schema.SObjectField> fsMap = descResult[0].fields.getMap();
List<String> fieldNames = new List<String>(fsMap.keySet());
for(String f:fieldNames){
System.debug(f);
}
String queryString = 'SELECT '+String.join(fieldNames, ',')+' FROM '+objTypeName+' LIMIT 1';
SObject obj = Database.query(queryString);
System.debug(obj);
}
}
In Execute Method: Call ExtractFields.queryAllFields(Account);
public static void queryAllFields(String objTypeName) {
Schema.DescribeSObjectResult[] descResult =
Schema.describeSObjects(new String[]{objTypeName});
Map<String, Schema.SObjectField> fsMap = descResult[0].fields.getMap();
List<String> fieldNames = new List<String>(fsMap.keySet());
for(String f:fieldNames){
System.debug(f);
}
String queryString = 'SELECT '+String.join(fieldNames, ',')+' FROM '+objTypeName+' LIMIT 1';
SObject obj = Database.query(queryString);
System.debug(obj);
}
}
In Execute Method: Call ExtractFields.queryAllFields(Account);
No comments :
Post a Comment