Last active
December 23, 2015 18:19
-
-
Save RoyGilad/6674933 to your computer and use it in GitHub Desktop.
Field set are also useful when creating an integration: You can add and remove fields from the exposed API, without changes in the code, for example in the code below we have created a field set for the Account object named “IntegrationFields”:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Salesforce Force.com Apex example: integration using field-set | |
@RestResource(urlMapping='/Account/*') | |
global with sharing class MyRestResource { | |
@HttpGet | |
global static Account doGet() { | |
RestRequest req = RestContext.request; | |
RestResponse res = RestContext.response; | |
String accountId = req.requestURI.substring(req.requestURI.lastIndexOf('/')+1); | |
String query = 'SELECT '; | |
for(Schema.FieldSetMember f : SObjectType.Account.FieldSets.IntegrationFields.getFields()) | |
{ | |
query += f.getFieldPath() + ', '; | |
} | |
query += 'Id FROM Account where ID=\''+ id +'\' LIMIT 1'; | |
Account result = Database.query(query); | |
return result; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment