The use case is a trigger calls(enqueues) a Queueable job. The code is failing and I did some debugging and figured out that it is running in user context. I thought asynchronous jobs run in system context. Is it possible to run a Queueable job in system context?

This is my use case

A partner community user creates an account and we need to transfer the ownership to internal user and then grant Read permission to community user who created it. In the Account trigger, I change the owner to internal user but can't insert a row into AccountShare due to the error "INSUFFICIENT_ACCESS_ON_ CROSS_REFERENCE_ENTITY". After debugging, I realized that the community user already has access to account because the record with new owner in not committed yet. So in the trigger I change the ownership and in the queuable job, I am inserting a row into AccountShare for community user but I still get "INSUFFICIENT_ACCESS_ON_ CROSS_REFERENCE_ENTITY" error in the queueable job.

1 Answer 1


If your class specifies "with sharing", it runs in user context. Otherwise, it should run in system context. You may want to use "without sharing" to make sure it runs in system context.

  • Thanks but it still runs in user context. The trigger calls TriggerHandler which has "without sharing" and the handler calls queueable job. I also used "without sharing" on the queueable class. For debugging, I am logging the user info in queueable class. It prints the user who modified the record initially.
    – sdondeti
    Commented Dec 23, 2015 at 20:07
  • 2
    @sdondeti "system context" doesn't change the running user. It simply runs with relaxed permissions. There's no way to make any live code run as any arbitrary user.
    – sfdcfox
    Commented Dec 24, 2015 at 0:33
  • @sdondeti What is the permission that you want to override using system context? As without sharing is more around record level relaxations.
    – SEuser
    Commented Dec 24, 2015 at 9:04
  • @kaushik Ray, I updated the question with the use case above.
    – sdondeti
    Commented Dec 24, 2015 at 12:28
  • @sfdcfox don't all triggers run in system context regardless and the use of with sharing and without sharing in called classes only affects row-level access and not permissions (OLS/FLS)? For reference: salesforce.stackexchange.com/a/172130/12290 Commented Aug 30, 2022 at 15:47

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .