From bace0b00ccb12679ccccfaad67f3abd2e87b0a90 Mon Sep 17 00:00:00 2001 From: Kazuki Nakajima Date: Sat, 13 Jul 2013 18:01:26 +0900 Subject: [PATCH] retrieve all fields if fieldlist is null added small code to retrieve method to retrieve all fields if fieldlist is null. --- RemoteTKController.cls | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/RemoteTKController.cls b/RemoteTKController.cls index 859cd3a..d20b0f4 100644 --- a/RemoteTKController.cls +++ b/RemoteTKController.cls @@ -160,7 +160,22 @@ public class RemoteTKController { @remoteAction public static String retrieve(String objtype, String id, String fieldlist) { - // TODO - handle null fieldlist - retrieve all fields + // retrieve all fields if fieldlist is null + if (fieldlist == null){ + fieldlist = ''; + 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 fieldMap = sobjResult.fields.getMap(); + for (String key : fieldMap.keySet()) { + Schema.DescribeFieldResult descField = fieldMap.get(key).getDescribe(); + fieldlist += descField.getName() + ','; + } + fieldlist = fieldlist.removeEnd(','); + } + Boolean containsId = false; for (String field : fieldlist.split(',')) { if (field.equalsIgnoreCase('id')){ @@ -291,4 +306,4 @@ public class RemoteTKController { return JSON.serialize(result); } -} \ No newline at end of file +}