In the previous article we have learned about How to Fetch All Object API Names Using Dynamic Apex in Salesforce which you can read from here. In this article I will tell you How to check Object Permission Using Dynamic Apex?
One of the best practice which developer should follow while writing Apex code is to check the object permission before performing any CRUD operations. If we don’t check object permission then a user without the permission will perform changes in the Salesforce database.
Here is the code which will help you check create, read, edit and delete permission for Contact SObject. You just need to replace the API Name of the object for which you want to check specific permission.
//Checking if the Logged In User has permission to create Contact Records. if(Schema.SobjectType.Contact.iscreateable()){ System.debug('User has permission to create Contact Records'); } //Checking if the Logged In User has permission to update Contact Records. if(Schema.SobjectType.Contact.isupdateable()){ System.debug('User has permission to update Contact Records'); } //Checking if the Logged In User has permission to delete Contact Records. if(Schema.SobjectType.Contact.isdeletable()){ System.debug('User has permission to delete Contact Records'); } //Checking if the Logged In User has permission to query/access Contact Records. if(Schema.SobjectType.Contact.isaccessible()){ System.debug('User has permission to query Contact Records'); }
When you execute the above code from the anonymous window and open debug logs you will see the different logs based on the permission given to that specific profile in your Salesforce Org. Here is what I saw when i executed the code.

In above code Schema.SObjectType represents metadata about a Salesforce object (e.g., Contact
, Account
, etc.). It provides access to details about the object, such as its fields, permissions, and more. Schema.SObjectType.Contact refers to the metadata of the Contact Object.
The above Apex code checks the logged-in user’s CRUD (Create, Read, Update, Delete) permissions on the Contact
object:
- Create Permission:
isCreateable()
checks if the user can createContact
records. - Update Permission:
isUpdateable()
checks if the user can updateContact
records. - Delete Permission:
isDeleteable()
checks if the user can deleteContact
records. - Read/Access Permission:
isAccessible()
checks if the user can view/queryContact
records.
Also check out the below video on How to check object permission using apex in salesforce?
We hope now you know How to check Object Permission using apex. If you have any doubts then let us know in the comment box below.