A synchronous Apex controller has an obvious security review: who can call it, does it respect sharing, does it check field access. Move the same logic into a Queueable or a Batch job and the review often stops, because nobody calls a job from a browser. But the job still reads and writes records, and it does so in a context that is easy to get wrong.
Asynchronous Apex starts a new transaction with no calling class to inherit a sharing mode from, it may run hours after the request that queued it, and it often runs over thousands of records at once. This post covers how sharing and access checks behave in Queueable, Batch, Schedulable and @future code, what changed at API version 67.0, and the patterns that hold up.
Every async job is a new entry point
When a controller calls a helper class synchronously, a helper with no sharing keyword inherits the controller's mode. When the same work is enqueued, the platform later calls execute itself. There is no caller left to inherit from.
Salesforce's guide to the sharing keywords spells out one consequence: asynchronous classes declared inherited sharing always run in with sharing mode, because each asynchronous operation is a new entry point and the sharing mode is not serialized with the job.
For a class with no sharing keyword at all, the answer depends on its API version:
| Class declaration | API 66.0 and earlier | API 67.0 and later |
|---|---|---|
with sharing |
Sharing enforced | Sharing enforced |
inherited sharing |
Sharing enforced in async | Sharing enforced in async |
| No keyword | Runs without sharing as an async entry point | Runs in the current user context (Summer '26 change) |
without sharing |
Sharing ignored | Sharing ignored |
The version is set per class in its -meta.xml, so a single org usually holds both behaviours. A Batch class written in 2021 at API 52.0 with no keyword still ignores sharing today. Declaring the keyword explicitly on every async class removes the guesswork.
Sharing is not field access
with sharing controls which records a query returns. It does not check object permissions or field-level security. Before API 67.0, plain SOQL and DML ran in system mode for those checks regardless of the sharing keyword.
From API 67.0, Salesforce runs database operations in user mode by default, and WITH SECURITY_ENFORCED is no longer allowed in Apex compiled at that version (see the versioned behaviour changes). On older classes, say it explicitly:
public with sharing class RecalculateDiscounts implements Queueable {
private final Set<Id> accountIds;
public RecalculateDiscounts(Set<Id> accountIds) {
this.accountIds = accountIds;
}
public void execute(QueueableContext ctx) {
List<Account> rows = [
SELECT Id, Discount_Tier__c FROM Account
WHERE Id IN :accountIds
WITH USER_MODE
];
for (Account a : rows) {
a.Discount_Tier__c = DiscountRules.tierFor(a);
}
update as user rows;
}
}Whose access is "user mode" in a job?
User mode enforces the running user of the job, which is normally the user whose transaction enqueued it. That is the right answer when a person clicks a button and the work is deferred. It is the wrong assumption in three common cases:
- Scheduled jobs run as whoever scheduled them, often an admin who set them up years ago. The Apex Scheduler documentation also notes that the scheduler runs as system, so the scheduled class executes whether or not that user has access to the class.
- Jobs started from platform event triggers run as the trigger's configured user, the Automated Process user unless you set a different one.
- Jobs chained from other jobs run as the same user as the job that enqueued them, so a chain started by an admin-owned scheduled job keeps admin rights all the way down.
Decide deliberately which user each job should run as, and make admin-owned scheduled jobs do admin work only.
Batch Apex: the query is checked once
A Batch start method that returns a QueryLocator can run in user mode:
public Database.QueryLocator start(Database.BatchableContext bc) {
return Database.getQueryLocator(
'SELECT Id, Email FROM Contact WHERE Opt_Out_Pending__c = true',
AccessLevel.USER_MODE
);
}The Database class reference adds a detail that matters for long jobs: the access level is evaluated only when the QueryLocator is created, and security is not re-evaluated on each iteration. A permission removed halfway through a batch does not stop the remaining chunks. The execute method should apply its own user-mode DML and, for sensitive writes, re-query what it needs.
Two related state bugs also show up in reviews. A Batch class that keeps member state without Database.Stateful silently resets it between chunks, so a counter or an "already processed" set is wrong. A Queueable that enqueues itself with no depth guard can chain until a limit stops it.
Pass IDs, not records
@future methods enforce part of this for you: their parameters must be primitives or collections of primitives, never sObjects. Apply the same rule to Queueables even though they allow sObject members:
- A record captured at enqueue time is a snapshot. By the time the job runs, the record may have changed owner, been shared differently or been deleted.
- A record built from request input can carry field values the caller set, and a job that later writes it with
updateperforms a mass assignment the caller could not have done directly. - Re-querying by ID inside the job, in user mode, applies the current sharing and field access to the current data.
// Risky: the job writes whatever the caller put in the records
System.enqueueJob(new SyncContacts(contactsFromRequest));
// Safer: the job reads current data itself, inside the user's access
System.enqueueJob(new SyncContacts(new Map<Id, Contact>(contactsFromRequest).keySet()));A review checklist for async classes
- Every Queueable, Batchable, Schedulable and
@futureclass declareswith sharingorinherited sharing, or documents why it iswithout sharing. - Queries and DML say
WITH USER_MODEandas user(or the class is at API 67.0 or later and does not opt out withWITH SYSTEM_MODEorAccessLevel.SYSTEM_MODE). - Job inputs are IDs and primitives, re-queried inside the job.
- The running user of each scheduled and event-driven job is known and appropriate.
- Nothing enqueues one job per record inside a loop, and self-chaining has a depth limit.
- Jobs that touch personal data log what they changed, not the data itself.
Where Vulkro for Salesforce fits
vulkro-sf scan treats async classes as entry points. apex-async-implicit-without-sharing flags a Queueable, Batchable, Schedulable or @future class with no sharing keyword that touches personal data, and apex-async-explicitly-without-sharing-on-sensitive-data flags one declared without sharing. Both are raised when the entry method writes that data without an enforced query. The version-aware apex-system-mode-optout rule applies too, flagging explicit system mode in classes compiled at 67.0 or later. The anti-pattern checks add AP-090 (Batch state without Database.Stateful, unguarded Queueable chaining) and AP-071 (System.enqueueJob inside a loop).
FAQ
Does a Queueable inherit the sharing mode of the class that enqueued it?
No. The job is a new entry point. Its own declaration decides, and inherited sharing resolves to with sharing in async context.
Does with sharing on a Batch class enforce field-level security?
No. Sharing controls record visibility. Use WITH USER_MODE, AccessLevel.USER_MODE and as user DML, or compile at API 67.0 or later where user mode is the default.
Can I pass sObjects to a @future method?
No. Future methods accept only primitives and collections of primitives. Pass record IDs and query inside the method.
See the Apex detectors and CRUD and FLS in Vulkro for Salesforce, or start a 14-day trial. Related: with sharing, without sharing and inherited sharing and Apex CRUD and FLS enforcement.