6

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.

5

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.

4
  • 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 Dec 23 '15 at 20:07
  • 1
    @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 Dec 24 '15 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. – Kaushik Ray Dec 24 '15 at 9:04
  • @kaushik Ray, I updated the question with the use case above. – sdondeti Dec 24 '15 at 12:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.