We have data in our in-house systems relating to Salesforce object records. We need to replicate the Salesforce permissions on the corresponding records in our systems.

I've been investigating retrieving the org-wide default sharing settings through Apex and am having the following issues:

  • I can get the default access for internal users for most standard objects from the Organization object; however, I cannot find a value for the Order object.
  • I cannot find the default access for external users for any object.
  • I cannot find the status of the check boxes (e.g., grant access to hierarchies, portal user visibility, etc.).
  • I cannot find where the configuration for the object sharing rules is stored.

I've checked the ObjectPermissions object and the CustomObject__Share objects, but those object don't hold the above information.

Can anyone point me to where I can query this information?

2 Answers 2


What you're looking for is the retrieve() call, which lets you specify metadata to get information you're looking for, including the org wide defaults for a given object, grant access via hierarchy options, etc. Note that some objects don't have sharing; they are controlled by the parent object(s) instead. For most of what you want, you will retrieve CustomObject, which also returns standard objects. If you also want Field Level Security, you must also retrieve Profile and PermissionSet.

  • Hmm. I was hoping for a SOQL query rather than an API call as we need to check the values frequently. Those settings don't change often; maybe I will cache the values we need into custom objects and refresh them either on demand or on a schedule. In any case, thanks for the information. It will take me a while to find where everything I need is stored, but I have the data now. Mar 2, 2021 at 15:05

You can query the Tooling API object EntityDefinition to get information about internal and external sharing models:

SELECT NamespacePrefix, DeveloperName, ExternalSharingModel, InternalSharingModel FROM EntityDefinition 

However, the other information you're interested in (as sfdcfox described) will probably require the Metadata API.

  • Thanks. That information is also available in the CustomObject method of the Metadata API which @sfdcfox pointed out above. I'll probably go with that just because the rest of the info is also exposed through that same API, but I appreciate the tip. Mar 3, 2021 at 16:31

You must log in to answer this question.

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