8

I am attempting to use the Tooling API to retrieve all the data for a particular profile. According to the Tooling API documentation from v32 there is a Profile object which contains a set of ProfileMetadata. I am running the following anonymous code:

HttpRequest req = new HttpRequest();
req.setHeader('Authorization', 'Bearer ' + UserInfo.getSessionID());
req.setHeader('Content-Type', 'application/json');
req.setEndpoint('https://na11.salesforce.com/services/data/v32.0/tooling/sobjects/Profile/00eA0000000WrUv');
req.setMethod('GET');
Http h = new Http();
HttpResponse res = h.send(req);
system.debug(res.getBody());

The profile being referenced is a custom profile with permissions on objects etc however the debug output is as shown at https://gist.github.com/pbattisson/7a20ebfbf0d6591f239f

As you can see certain data is not coming through (objectPermissions is what I need out of this) and I wondered if anybody had any idea how to get that data? Thanks.

  • 1
    Paul - I would be curious if this is related to the concept that the profile extracted by Metadata API only show the objects, classes, pages, etc that are part of the current API request. When you were making your API request, where you extracting other components? – ImJohnMDaniel Oct 31 '14 at 13:34
  • Nope, just extracting the single profile as per the Tooling API reference material. – pbattisson Oct 31 '14 at 13:39
  • Yep +1 for John's theory, basically the focus of my answer below, i cannot see a direct admission to it working this way in the Tooling API, unlike the Metadata API, but i strongly suspect it does work this way, my question though would be how to inject the list of objects, fields etc in the context of Tooling API.... ;-) – Andrew Fawcett Oct 31 '14 at 13:42
  • It may also be that the Metadata field on the Profile Tooling API is really only good for update and insert operations. I've reached out to one of the Tooling API devs via Twitter see if we can get some clarification. – Andrew Fawcett Oct 31 '14 at 13:46
  • Thanks for the assistance, will attempt to use the object model for retrieval as it stands. If we get anything from Salesforce confirming then will mark the answer. – pbattisson Oct 31 '14 at 13:48
5

My guess is Tooling API is suffering from the same internal affliction as the Metadata API when you attempt to retrieve a Profile, or PermissionSet for that matter. In that these operations require you to also retrieve the objects, fields, pages, classes etc you expect to be referenced in the Profile or Permission Set. The Metadata API docs describes this need as follows...

The content of a profile returned by Metadata API depends on the content requested in the RetrieveRequest message. For example, profiles only include field-level security for fields included in custom objects returned in the same RetrieveRequest as the profiles.

Alternative:

I've had this same need before, and simply switched to using direct SOQL, as fortunately Profiles being backed by Permission Sets, have very good exposure via the "standard objects" (in the context of this answer, those available via SOQL REST API or Apex SOQL). Take a look at the docs for the PermissionSet object and scroll down to see the ERD for the related objects.

In cases where i have needed to the XML representation of this information, i've simply hand cranked as an output from the code using the SOQL to read the information directly. The .profile and .permissionSet XML representations are not that complex thankfully.

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.