Skip to content

Instantly share code, notes, and snippets.

@RoyGilad
Last active December 23, 2015 18:19
Show Gist options
  • Save RoyGilad/6674933 to your computer and use it in GitHub Desktop.
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”:
//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