From 4cf56487be5a8c8f22500011424b40aa84f6e6e5 Mon Sep 17 00:00:00 2001 From: Pat Patterson Date: Mon, 1 Oct 2012 09:37:05 -0700 Subject: [PATCH] Only add Id to list of fields to be retrieved if it is not already there --- RemoteTKController.cls | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/RemoteTKController.cls b/RemoteTKController.cls index e651d01..2ae97b3 100644 --- a/RemoteTKController.cls +++ b/RemoteTKController.cls @@ -102,13 +102,20 @@ public class RemoteTKController { @remoteAction public static String retrieve(String objtype, String id, String fieldlist) { - // TODO - handle missing fieldlist - retrieve all fields - String fieldString = ''; + // TODO - handle null fieldlist - retrieve all fields + Boolean containsId = false; for (String field : fieldlist.split(',')) { - fieldString += ','+field; + if (field.equalsIgnoreCase('id')){ + containsId = true; + break; + } + } + + if (!containsId) { + fieldlist = 'Id,'+fieldlist; } - String soql = 'SELECT Id'+fieldString+' FROM '+objtype+' WHERE Id = \''+id+'\''; + String soql = 'SELECT '+fieldlist+' FROM '+objtype+' WHERE Id = \''+id+'\''; List records; try { records = Database.query(soql);