+ Start a Discussion

Determine OWD setting for an object



In apex, How can we determine OWD setting (Org Wide Defaults) for a particular object if we already know object name?







As per my knowledge, I dont think this metadata is exposed for Apex usage. The closest I could find, was the Descibe Result's methods, which could tell you the access of the object. These can be used to enforce current users permissions for Objects and Fields





Check these methods if you find them useful for your purpose here -





Please do share if you find anything else.




Jerun JoseJerun Jose

Agree with Ritika's comment.


If you really need to view this piece of the metadata, you might have to invoke the metadata API using a webservice call.

Not sure if it still works, but check out the thread at :



Other than these, what I can think, is to use Apex managed sharing to insert some test data into the sharing object for the object under consideration and then catching the exceptions appropriately to figure out the org wide setting.

Say like, if the share obj is not available, then OWD is public r/w , if inserting record with read access causes error, then OWD is public r, else its private..

Just some thoughts.. not sure if they can work.




Jerun Jose


Thanks Ritika, Jerun




I tried to catch the exception but it is not working. I've posted seperate post for that 



Can you please share your way of doing it?


Jerun JoseJerun Jose

Your post has some content which I believe has been taken from the developer's guide. I have only gone thru that content and did not implement it.


What I was suggesting was different way of exception handling using the try catch statements.


public static method getOWD(String objName){
	Savepoint sp = Database.setSavePoint();
	Boolean error = false;
	// Use global describe to check if Sobject exists with name provided
	// if no, then OWD is public r,w
	// if yes, then a generalised version of 
		SObject js = new Job__Share()
		// populate fields for your share record here. you could use the sObject.put methods
		insert js;
	catch(Exception ex){
		// check the exception contents here to see if OWD is public r
		error = true;
	if( !error)
	// OWD is private;






Your approach is nice but don't you think that not catching a specific exception might end up in wrong results? I hope you are getting my point. Because if error is occured due to some other means and not due to trivial access then it will display wrong results.

Jerun JoseJerun Jose

You are absolutely right Jagdeep.


I just put that to display the format. I really do not know what exception category it will throw.. probably a DMLException.

The way I do it is to debug the exception once, and then know what its contents are.


And then when developing the logic, check for exactly that exception and handling it.