0

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?

1

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.

1
  • 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. – silverglass Mar 2 at 15:05
1

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.

1
  • 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. – silverglass Mar 3 at 16:31

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.