FAQ-000128 - Batch Processing Security / Sharing Context and Permissions

Current Status:VALID_RESPONSEErrorUnable to AnswerSuggests Case

Current FAQ

Question
What is the recommended sharing model for Apex batch jobs that need to process records regardless of ownership or perform maintenance tasks?
Answer
The recommended sharing model for Apex batch jobs that need to process records regardless of ownership is to use the **"without sharing"** keyword. This ensures the batch job runs in system mode, bypassing sharing rules and allowing access to all records. To handle a batch job that needs to perform maintenance on records regardless of the running user's sharing permissions: 1. Implement the batch job in a class declared as **"without sharing"** to run in system mode, bypassing sharing rules and allowing access to all records. 2. Enforce **CRUD/FLS checks** within the code to ensure compliance with field-level and object-level security. 3. Carefully evaluate the business justification for bypassing sharing rules and document the use case to address potential security concerns. 4. Make sure to implement proper CRUD/FLS checks to comply with security requirements. This approach should be used cautiously to avoid exposing or modifying restricted data, and proper documentation of the use case and justification for using **"without sharing"** is important, especially if the batch job is part of an AppExchange package undergoing a security review.
Enhancing FAQ...

Enhancing FAQ with AI recommendations...

AI Recommended Enhancement

Related Security Rules (click to view)
ApexSharingViolationsApexCRUDViolation
Question
What is the recommended sharing model for Apex batch jobs that need to process records regardless of ownership or perform maintenance tasks?
Recommended Answer Update
The recommended sharing model for Apex batch jobs that need to process records regardless of ownership is to use the **"without sharing"** keyword. This ensures the batch job runs in system mode, bypassing sharing rules and allowing access to all records. To handle a batch job that needs to perform maintenance on records regardless of the running user's sharing permissions: 1. Implement the batch job in a class declared as **"without sharing"** to run in system mode, bypassing sharing rules and allowing access to all records. 2. Enforce **CRUD/FLS checks** within the code to ensure compliance with field-level and object-level security. 3. Carefully evaluate the business justification for bypassing sharing rules and document the use case to address potential security concerns. 4. Make sure to implement proper CRUD/FLS checks to comply with security requirements. This approach should be used cautiously to avoid exposing or modifying restricted data, and proper documentation of the use case and justification for using **"without sharing"** is important, especially if the batch job is part of an AppExchange package undergoing a security review.
Reasoning
The FAQ content is accurate and well-structured. No significant changes are needed as the existing content properly addresses sharing contexts and security requirements for batch jobs. The answer correctly emphasizes using 'without sharing' for system-level batch operations while stressing the importance of CRUD/FLS checks. For ApexSharingViolations: This rule is directly relevant because the FAQ discusses the deliberate use of 'without sharing' keyword to bypass sharing rules in batch jobs. The FAQ content specifically addresses when and why to use 'without sharing', which is exactly what this rule monitors for potential security violations. The FAQ's emphasis on documentation and business justification aligns with addressing concerns this rule would raise. For ApexCRUDViolation: This rule is highly relevant because the FAQ repeatedly emphasizes implementing 'CRUD/FLS checks within the code' and 'proper CRUD/FLS checks to comply with security requirements.' The FAQ specifically mentions field-level and object-level security enforcement, which is precisely what this rule validates in Apex code.
Reasoning References
Recommended Related Articles