Skip to content
This repository was archived by the owner on Jan 10, 2024. It is now read-only.
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion RemoteTKController.cls
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ public class RemoteTKController {
@remoteAction
public static String create(String objtype, String fields) {
Schema.SObjectType targetType = Schema.getGlobalDescribe().get(objtype);
Map<String, Schema.sObjectField> targetFields = targetType.getDescribe().fields.getMap();
if (targetType == null) {
return '[{"message":"The requested resource does not exist","errorCode":"NOT_FOUND"}]';
}
Expand All @@ -73,7 +74,18 @@ public class RemoteTKController {

try {
for (String key : fieldMap.keySet()) {
obj.put(key, fieldMap.get(key));
if (targetFields.get(key).getDescribe().getType() == Schema.DisplayType.Date) {
obj.put(key, Date.valueOf((String)fieldMap.get(key)));
} else if (targetFields.get(key).getDescribe().getType() == Schema.DisplayType.Percent ||
targetFields.get(key).getDescribe().getType() == Schema.DisplayType.Currency) {
obj.put(key, String.valueOf(fieldMap.get(key)) == '' ? null : Decimal.valueOf((String)fieldMap.get(key)));
} else if (targetFields.get(key).getDescribe().getType() == Schema.DisplayType.Double) {
obj.put(key, String.valueOf(fieldMap.get(key)) == '' ? null : Double.valueOf(fieldMap.get(key)));
} else if (targetFields.get(key).getDescribe().getType() == Schema.DisplayType.Integer) {
obj.put(key, Integer.valueOf(fieldMap.get(key)));
} else {
obj.put(key, fieldMap.get(key));
}
}
} catch (SObjectException soe) {
return '[{"message":"'+soe.getMessage()+'","errorCode":"INVALID_FIELD"}]';
Expand Down