Is there a way to know programmatically which objects have role access enabled, i.e "Grant Access Using Hierarchies" enabled in Organization-Wide defaults? I didn't find this information when querying the METADATA API or the SOAP API.

I can only use java code for this project, thus Apex solutions are not possible.

Thank you.

  • Did you find a way to get this done @nicolas42?
    – Patlatus
    Oct 18 '19 at 12:45

Unfortunately it seems that Org-Wide Defaults are on the list of components that are unable to be retrieved via the Metadata API. Here's a full list of these for your reference: Unsupported Metadata Types

  • 1
    This page seems to not be updated correctly. It is written that "Sharing Organization Wide Defaults" cannot be retrieved. However I managed to access Custom objects OWD visibility by querying "CustomObject" with the Metadata API. It returns ".object" files containing a field "sharingModel" which has custom objects visibility. customobject.htm If custom objects visibility is retrievable maybe the hierarchy sharing is too.
    – nicolas42
    Jul 17 '13 at 14:09

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

public static List<String> getObjectsHavingGrantAccessUsingHierarchies() {
String u = URL.getSalesforceBaseUrl().toExternalForm() + 
PageReference p = new PageReference(u);
String x = p.getContent().toString().substringBetween('class="pbBody">','</div');
List<string> xx = x.split('</tr>');
Map<String, Boolean> entityLabelToCheckbox = new Map<String, Boolean>();
for (String xxx: xx) {
    String a = xxx.substringBetween('class=" dataCell  ">', '</th>');
    String b = xxx.substringBetween(' booleanColumn">', '</td>');
    if (!String.isBlank(b)) {
        Boolean c = b.contains('/img/checkbox_checked.gif');
        entityLabelToCheckbox.put(a, c);

List<String> with = new List<String>();
List<String> without = new List<String>();

for (String label: entityLabelToCheckbox.keySet() ) {
    if (entityLabelToCheckbox.get(label)) {
    } else {


 return with;

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

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.