4

Is there any way to retrieve the "Grant Access Using Hierarchies" setting programmatically (i.e. through Metadata, SOQL, or other means)?

I am referring to the checkbox next to each object under Setup->Sharing Settings for Organization-Wide Defaults.

Through Metadata api, I can use the readMetadata method for each object to get the sharingModel and externalSharingModel attributes (i.e. Default Internal Access and Default External Access). However, I do not see any attribute that corresponds with "Grant Access Using Hierarchies".

Thanks,

Mike

3
  • @[mike-paisner] did you find any solution to this?
    – Patlatus
    Oct 18, 2019 at 10:48
  • @Patlatus No, I never found a solution. Oct 21, 2019 at 15:15
  • I have fragile solution which I have described in my answer, also opened a Salesforce idea for Salesforce to implement some better solution
    – Patlatus
    Oct 21, 2019 at 15:29

1 Answer 1

2

Looks like this option is not available neither by Apex, nor by Tooling API, SOAP API or Metadata API. So the only option I have found to achieve this is screen-scraping.

public static Boolean hasGrantAccessUsingHierarchies(String entityName) {

    String entityId = [SELECT DurableId FROM Entitydefinition WHERE DeveloperName = :entityName].DurableId;

    String u = URL.getSalesforceBaseUrl().toExternalForm() + 
        '/p/own/OrgSharingDetail?setupid=SecuritySharing&div_filter=&st=' + entityId;
    PageReference p = new PageReference(u);
    String x = p.getContent().toString();
    String y = x.substringBetween(' booleanColumn">', '</td>');
    Boolean z = y.contains('/img/checkbox_checked.gif');
    return z;
}

Anonymous script:

String entityName = 'CustomObject';
System.debug(hasGrantAccessUsingHierarchies(entityName));

However, this might not pass Security Review, since this is fragile as any screen-scraping methods.

Also I posted idea to get a better option https://success.salesforce.com/ideaView?id=0873A0000015AhkQAE

You must log in to answer this question.

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