You need to sign in to do that
Don't have an account?
Jayaramu T 9
Hi All, following code returns a dynamic SOQL statement for the hole CASE object. but i want only some fields like Account Name,Contact Name,Subject,Issue Summary,Case Record Typeof case object. can any one please help me on this
// Returns a dynamic SOQL statement for the whole object, includes only creatable fields since we will be inserting a cloned result of this query
public static string getCreatableFieldsSOQL(String objectName){
String selects = '';
//if (whereClause == null || whereClause == ''){ return null; }
// Get a map of field name and field token
Map<String, Schema.SObjectField> fMap = Schema.getGlobalDescribe().get(objectName.toLowerCase()).getDescribe().Fields.getMap();
list<string> selectFields = new list<string>();
if (fMap != null){
for (Schema.SObjectField ft : fMap.values()){ // loop through all field tokens (ft)
Schema.DescribeFieldResult fd = ft.getDescribe(); // describe each field (fd)
//if (fd.isCreateable()){ // field is creatable
selectFields.add(fd.getName());
//}
}
}
if (!selectFields.isEmpty()){
for (string s:selectFields){
selects += s + ',';
}
if (selects.endsWith(',')){selects = selects.substring(0,selects.lastIndexOf(','));}
}
return 'SELECT ' + selects + ' FROM ' + objectName;
}
public static string getCreatableFieldsSOQL(String objectName){
String selects = '';
//if (whereClause == null || whereClause == ''){ return null; }
// Get a map of field name and field token
Map<String, Schema.SObjectField> fMap = Schema.getGlobalDescribe().get(objectName.toLowerCase()).getDescribe().Fields.getMap();
list<string> selectFields = new list<string>();
if (fMap != null){
for (Schema.SObjectField ft : fMap.values()){ // loop through all field tokens (ft)
Schema.DescribeFieldResult fd = ft.getDescribe(); // describe each field (fd)
//if (fd.isCreateable()){ // field is creatable
selectFields.add(fd.getName());
//}
}
}
if (!selectFields.isEmpty()){
for (string s:selectFields){
selects += s + ',';
}
if (selects.endsWith(',')){selects = selects.substring(0,selects.lastIndexOf(','));}
}
return 'SELECT ' + selects + ' FROM ' + objectName;
}