Skip to content
This repository has been archived by the owner on Jan 10, 2024. It is now read-only.

retrieve all fields if fieldlist is null #39

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
19 changes: 17 additions & 2 deletions RemoteTKController.cls
Original file line number Diff line number Diff line change
Expand Up @@ -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<String, Schema.SObjectField> 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')){
Expand Down Expand Up @@ -291,4 +306,4 @@ public class RemoteTKController {

return JSON.serialize(result);
}
}
}