Is it possible to know, via apex code, if a certain object is Private, Public Read-Only or Public Read/Write?
- Anybody can ask a question
- Anybody can answer
- The best answers are voted up and rise to the top
For the Standard object, you can use Organization object to achieve this, query like,
Organization org = [Select Id, DefaultAccountAccess, DefaultContactAccess, DefaultLeadAccess, DefaultOpportunityAccess from Organization];
Query this object to obtain information about an organization's settings. Only one organization object exists per organization.
for the details, see the doc, http://www.salesforce.com/us/developer/docs/api/Content/sforce_api_objects_organization.htm
Another way to test for sharing of custom objects is to check the global describe Map.
As you have already discovered, this is only for custom objects, @JiaHu's answer explains how to get the sharing level of a standard object.
Guess this should help you :
SELECT Id,ParentId,UserOrGroupId,RowCause,AccessLevel FROM ObjectApiName__Share