Ask a Question
Ask Question Login
Corporate Training
  1. Community
  2. Salesforce
  3. Question
Salesforce

How can I validate CRUD permission before execution of the SOQL queries or DML operation?

Asked by Deepa Bhawana Mar 27, 2024 3.2K views 3 answers
Share

About this question

I am currently engaged in a particular task that is related to developing a Salesforce application where users have different levels of access based on their roles. How can I validate CRUD permission before implementation of the SOQL queries or DML operations to ensure that users can only perform actions they are authorized for? 

Your answer

3 Answers

Ranjana Admin JanBask Expert Latest answer

Answered on Feb 21, 2025

Validating CRUD (Create, Read, Update, Delete) permissions before executing SOQL queries or DML operations in Salesforce is essential for security and compliance. Here’s how you can do it:


1. Use Schema.sObjectType for CRUD Permission Checks

Before performing SOQL or DML, check if the user has the necessary permissions using the Schema.sObjectType methods.

Example: Check Permissions Before Insert

if (Schema.sObjectType.Account.isCreateable()) {
    Account acc = new Account(Name = 'Test Account');
    insert acc;
} else {
    System.debug('User does not have create permission on Account');
}

Was this helpful?

Michellegrant

Answered on Feb 4, 2025

Use isReadable() and isUpdateable() to confirm among us access to those fields.

Was this helpful?

More Salesforce discussions

Learn & Explore

Free tutorials and interview questions from industry experts — learn the skill, then get ready to prove it.

Latest Salesforce Blogs

Guides, tips and career advice on Salesforce from JanBask experts.