-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathobjectinfo.cls
35 lines (29 loc) · 1.06 KB
/
objectinfo.cls
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
public class objectinfo {
// Find the fields for the selected object
public static Map<String,Schema.DisplayType> showFields(String selectedObject) {
Map <String,Schema.DisplayType> customfields = new Map <String,Schema.DisplayType>();
// Map of all SObjects in the running SF Org
Map <String, Schema.SObjectType> schemaMap = Schema.getGlobalDescribe();
if (schemaMap.get(selectedObject)== null)
// system.debug('Non existent object');
return customfields;
else
{
// Map of field names
Map <String, Schema.SObjectField> fieldMap = schemaMap.get(selectedObject).getDescribe().fields.getMap();
//List <String> customfields = new List <String>();
for(Schema.SObjectField sfield : fieldMap.Values())
{
schema.describefieldresult dfield = sfield.getDescribe();
if (dfield.isCustom () ) {
// save custom field name without the __c suffix
system.debug(dfield.getType());
customfields.put(dfield.getname().left(dfield.getname().length()-3),dfield.getType());
}
}
//for (String fieldname : customfields)
// { system.debug(fieldname); }
return customfields;
}
}
}