we are using remoteTK on a salesforce project and its working great except for one very specific issue.
We are hitting governor limits with describes for one of the objects. IT has 150 picklists fields and the method thats getting all those picklists is returning an error.
This is the way the function is written right now is below. You can also see the full file here: https://github.com/developerforce/Force.com-JavaScript-REST-Toolkit/blob/master/RemoteTK.component
The limits are being hit on this line List picklistValues = field.getPicklistValues();
any ideas on hwo to get around it? Maybe the best way is to pass in a list of all the fields i need it ot describe and check against those? I don't need all 150 picklists in this app but not totally sure the best way to go about that?
public static String describe(String objtype) {
// Just enough to make the sample app work!
Schema.SObjectType targetType = Schema.getGlobalDescribe().get(objtype);
if (targetType == null) {
return makeError('The requested resource does not exist', 'NOT_FOUND');
}
Schema.DescribeSObjectResult sobjResult = targetType.getDescribe();
Map<String, Schema.SObjectField> fieldMap = sobjResult.fields.getMap();
List<Object> fields = new List<Object>();
for (String key : fieldMap.keySet()) {
Schema.DescribeFieldResult descField = fieldMap.get(key).getDescribe();
Map<String, Object> field = new Map<String, Object>();
field.put('type', descField.getType().name().toLowerCase());
field.put('name', descField.getName());
field.put('label', descField.getLabel());
List<String> references = new List<String>();
for (Schema.sObjectType t: descField.getReferenceTo()) {
references.add(t.getDescribe().getName());
}
if (!references.isEmpty()) {
field.put('referenceTo', references);
}
field.put('picklistValues', picklistOptions(descField));
fields.add(field);
}
Map<String, Object> result = new Map<String, Object>();
result.put('fields', fields);
return JSON.serialize(result);
}
private static List<Object> picklistOptions(Schema.DescribeFieldResult field) {
List<Object> picklistOptions = new List<Object>();
Schema.DisplayType fieldType = field.getType();
if (fieldType != Schema.DisplayType.Picklist &&
fieldType != Schema.DisplayType.MultiPicklist &&
fieldType != Schema.DisplayType.Combobox) {
return picklistOptions;
}
List<Schema.PicklistEntry> picklistValues = field.getPicklistValues();
for (Schema.PicklistEntry picklistValue: picklistValues) {
Map<String, Object> picklistOption = new Map<String, Object>();
picklistOption.put('value', picklistValue.getValue());
picklistOption.put('label', picklistValue.getValue());
picklistOption.put('active', picklistValue.isActive());
picklistOption.put('defaultValue', picklistValue.isDefaultValue());
picklistOptions.add(picklistOption);
}
return picklistOptions;
}