1

Can a protected custom setting be created, read, updated, and deleted from the REST API? Is it the same REST API that is used for SObjects?

2

You can definitely execute CRUD via the REST API for a Protected Custom Setting - but I ended up writing a custom REST class that receives some JSON, checks for an existing record in the C/S, and then executes the create/update.

kwzdso_ZDMoAuthSettings_c is my custom setting in the package:

@RestResource(urlMapping='/zdmsettings')
global class KWD_aSyncSettings {

     @HttpPost
     global static void setAPITokens() {

        String sResponse = RestContext.request.requestBody.toString();
        Map<String, Object> m = (Map<String, Object>)JSON.deserializeUntyped(sResponse);     

        Map<String, kwzdso__ZDMoAuthSettings__c> zdmoauth =  kwzdso__ZDMoAuthSettings__c.getall();

        kwzdso__ZDMoAuthSettings__c zdmnew;
        if (zdmoauth.size()  == 0) {//Empty
            zdmnew = new kwzdso__ZDMoAuthSettings__c();
            zdmnew.Name = 'ZDM';
            zdmnew.kwzdso__Endpoint__c = (String)m.get('instance_url');
            zdmnew.kwzdso__Refresh_Token__c = (String)m.get('refresh_token');
        }
        else {
            zdmnew = zdmoauth.get('ZDM');
            zdmnew.kwzdso__Endpoint__c = (String)m.get('instance_url');
            zdmnew.kwzdso__Refresh_Token__c = (String)m.get('refresh_token');
       }

        upsert zdmnew;

        RestContext.response.responseBody = Blob.valueOf('ok');

     }
}
  • 1
    Is this a protected custom setting from a managed package, as i am pretty sure the platform should prevent these from being seen by Apex outside of the package? – Andrew Fawcett Feb 7 '14 at 20:03
  • @AndrewFawcett You're right. That's why there's the custom rest service. Without it, the settings are not accessible outside whatever UI the managed package presents to the user. – sfdcfox Feb 7 '14 at 20:38
  • Correct - the package in question is setup as a site wide licence - and then we use a ConnectedApp to generate an oauth token. What I haven't tested is if a user without access to the package can post to the rest service = I assume no, but you never know with these things... – BritishBoyinDC Feb 7 '14 at 23:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.