You need to sign in to do that
Don't have an account?
Raksha Narayan
Find the datatype of each field from list<string>
I have a map<string,list<string>> storing list of objects and its fields. fir example: {{opportunity= name,stageName},{account=name,city__c},{case=name,casenumber}}and so on.. From the list<string> i want to find out the datatype of each field. Is that possible?
I tried iterating on the map value as follows:
for(List<String> m: mapfil.values()){
Schema.DisplayType fielddataType = m.getDescribe().getType(); }
But it throws error message saying: "Method does not exist or incorrect signature: void getDescribe() from the type List<String>".
Please help
I tried iterating on the map value as follows:
for(List<String> m: mapfil.values()){
Schema.DisplayType fielddataType = m.getDescribe().getType(); }
But it throws error message saying: "Method does not exist or incorrect signature: void getDescribe() from the type List<String>".
Please help
Schema.SObjectField field = FsMap.get(fieldName);
for(String m:mapfil.keySet()){
Schema.DescribeSObjectResult d = m.sObjectType.getDescribe();
Map<String, Schema.SObjectField> FsMap = d.fields.getMap();
for(String fieldName : FsMap.keySet()) {
Schema.SObjectField field = FsMap.get(fieldName);
Schema.DescribeFieldResult f = field.getDescribe();
system.debug(fieldName + ' label:' + f.getlabel() + ' type:' + f.getType());
}
}
But it throws error: Variable does not exist: sObjectType. Please help here
The below code works but this holds all the fields on opportunity,account,case. But i want it to hold only 2-3 fields for example {{opportunity= name,stageName},{account=name,city__c},{case=name,casenumber}} as it is increasing the heap size. Can you please help here?
for(string objectname:mapfil.keySet()){
String objType=objectname;
Map<String, Schema.SObjectType> schemaMap = Schema.getGlobalDescribe();
Schema.SObjectType leadSchema = schemaMap.get(objType);
Map<String, Schema.SObjectField> fieldMap = leadSchema.getDescribe().fields.getMap();
for (String fieldName: fieldMap.keySet()) {
//get all the fields label for Account Object
String fieldLabel = fieldMap.get(fieldName).getDescribe().getLabel();
//get data types for each fields
Schema.DisplayType fielddataType = fieldMap.get(fieldName).getDescribe().getType();
system.debug('fielddataType'+fielddataType);
system.debug(' label:' + fieldLabel + ' type:' + fielddataType);
}
}
Can you please help here?
Project of Salesforce (open source) :
https://github.com/jlantz/Cumulus/blob/dev/src/classes/UTIL_Describe.cls