I'm trying to list the Record Types per Permission Set. Unfortunately, this cannot be done through SOQL Query (IIRC).
That said, can somebody help me on how to achieve this through Metadata API (or others)?
Thank you!
Salesforce Stack Exchange is a question and answer site for Salesforce administrators, implementation experts, developers and anybody in-between. It only takes a minute to sign up.
Sign up to join this communityI'm trying to list the Record Types per Permission Set. Unfortunately, this cannot be done through SOQL Query (IIRC).
That said, can somebody help me on how to achieve this through Metadata API (or others)?
Thank you!
It is possible to be retrieved through Metadata API. To use this code you need to have MetadataService class from https://github.com/financialforcedev/apex-mdapi/blob/master/apex-mdapi/src/classes/MetadataService.cls
For this example you should include YOUR_PERMISSION_SET_API_NAME_HERE
in placeholder the list to be retrieved. You can also request up to 10 permission sets in one callout.
MetadataService.MetadataPort service = new MetadataService.MetadataPort();
service.SessionHeader = new MetadataService.SessionHeader_element();
service.SessionHeader.sessionId = UserInfo.getSessionId();
service.CallOptions = new MetadataService.CallOptions_element();
service.timeout_x = 120000;
List<MetadataService.PermissionSet> permissionSets = (List<MetadataService.PermissionSet>) service.readMetadata('PermissionSet', new List<String>{'YOUR_PERMISSION_SET_API_NAME_HERE'}).getRecords();
for (MetadataService.PermissionSet permissionSet_i : permissionSets) {
for (MetadataService.PermissionSetRecordTypeVisibility recordType_i : permissionSet_i.recordTypeVisibilities) {
System.debug(recordType_i.recordType + ' is visible: ' + recordType_i.visible);
}
}