2

My goal is to get all profiles (including customs) including all permissions and settings. I try to first get all profiles and then iterate over it to retrieve all permissions and settings.

However, I'm able to query readMetadata() by fullName only. If a profile has the same name, I only get the standard one.

I'd need another way to achieve my goal or is it possible to query by ID instead of fullName?

1

2 Answers 2

5

If it is subject to use the Metadata API only, I don't see a method to accept an ID instead of the fullName.

However, if you are able to also use the REST API, the URL to retrieve data of a particular profile by ID is (API version can be changed):

/services/data/v49.0/sobjects/Profile/{ID}

If you need to find the ID of all profiles, the URL is:

/services/data/v49.0/query/?q=select+Id+from+Profile

To describe the metadata of Profile, the URL is:

/services/data/v49.0/sobjects/Profile/describe

Updated to provide more examples on retrieving Tab Visibilities, Field Permissions, Layout Assignments, etc. of a particular profile by its ID.

The core idea is to find the relevant SObjects representing the meta and leverage the SOQL query in REST APIs (some of them are Tooling REST).

To retrieve the tab visibilities of a profile:

/services/data/v49.0/query/?q=SELECT+Id,+Name,+Visibility+FROM+PermissionSetTabSetting+where+Parent.Profile.Id+=+'00e0p000000WhKwAAK'

To retrieve the field permissions of a profile:

/services/data/v49.0/query/?q=SELECT+Id,+ParentId,+SobjectType,+Field,+PermissionsEdit,+PermissionsRead,+Parent.ProfileId+FROM+FieldPermissions+WHERE+Parent.IsOwnedByProfile+=+true+and+Parent.ProfileId+=+'00e0p000000WhKwAAK'+ORDER+BY+SObjectType,+Field

To retrieve the layout assignments is more complex. The first step is to find the RecordTypeId of a ProfileLayout relevant to the profile by (note that the URL contains /tooling):

/services/data/v49.0/tooling/query?q=select+LayoutId,+RecordTypeId,+TableEnumOrId+from+ProfileLayout+where+ProfileId+=+'00e0p000000WhKwAAK'

Then find the actual layout meta from its relevant SObject by using the following URL (take Account for an example; and append the RecordTypeId, not ID of the ProfileLayout in the above step)

/services/data/v49.0/sobjects/Account/describe/layouts/{RecordTypeIdOfProfileLayout}
5
  • Thanks. The problem is with the rest API, many fields are missing like Page Layouts, Field-Level Security, Tab Settings etc. How can I get the whole profile?
    – Julian
    Nov 30, 2020 at 8:53
  • 1
    Hi @Julian, I see. In theory, you can retrieve all related metadata about a particular profile using REST APIs (some of them are Tooling REST). I will update my answer with a few more examples. The downside is that it needs several round trip API calls and you need to find all relevant sobjects representing the meta. You can leverage the Composite Resources to reduce the number of API calls though.
    – Chun
    Nov 30, 2020 at 12:02
  • One last question regarding the last step: How do you know that you've to query Account here? What else is necessary to query?
    – Julian
    Dec 1, 2020 at 15:48
  • <records xsi:type="sf:ProfileLayout"> <sf:Id xsi:nil="true" /> <sf:LayoutId>00h1U000003aCLhQAM</sf:LayoutId> <sf:RecordTypeId>0121U0000010tu6QAA</sf:RecordTypeId> <sf:TableEnumOrId>Metric</sf:TableEnumOrId> </records> This is what I get back, for example.
    – Julian
    Dec 1, 2020 at 16:19
  • Hi @Julian, the second last query (on ProfileLayout), it returns the TableEnumOrId field which tells you what object each row is about. I chose the first one for the example which happens to be the Account. If you loop through the ProfileLayout query result, it should be able to query other things available to that profile and optionally filter out what you need.
    – Chun
    Dec 2, 2020 at 1:06
0

listMetadata() would give you all the profiles, including their Id and full name values. retrieveMetadata() only accepts fullName, however, but you can choose to use * to retrieve all profiles at once. However, it is generally ill-advised to name a custom profile the same name as a standard one because of the reason you've discovered. You can't specify a fullName to get to the custom profile if shadowed by a standard profile name.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .