0

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!

1 Answer 1

1

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.

Here is the documentation.

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);
    }
}

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.