The requirement is basically to run a query to update a number on a user custom field. The problem is that this code is being run on a trigger which has the after insert and after update events and the INSUFFICIENT_ACCESS_ON_CROSS_REFERENCE_ENTITY error is being thrown.

I already tried using without sharing on the class (which is a trigger handler).

  • Did you enable access to that custom field for portal user?
    – kurunve
    Commented Jul 18, 2017 at 17:59
  • You could move to something async, where there are several options which allow you to specify the context user.
    – Adrian Larson
    Commented Jul 18, 2017 at 18:01
  • @kurunve The portal user shouldn't have access to the user object, I believe. But I think that's worth a try. Commented Jul 18, 2017 at 18:06
  • @AdrianLarson could you please provide on how to specify the context user on async calls? Commented Jul 18, 2017 at 18:06
  • 1
    Well you can log in as someone else to schedule jobs, so that part's easy. Platform Event subscriber triggers also would probably work here if you want to go down that road.
    – Adrian Larson
    Commented Jul 18, 2017 at 18:07

1 Answer 1


My recommendation would be that you move to a scheduled rollup calculation. You can then impersonate whatever user you wish to schedule the job, preferably some sort of generic admin user. That way, the rollup will always be calculated by someone who should have all the appropriate permissions.

If you want it sooner, then you could try Platform Events. Here you might configure a long text field which contains newline delimited Id values (creatively named Ids__c), and then have a subscriber trigger calculate the rollups. This approach seems to have a similar time scale as @future invocations in my experience so far.

From your current trigger, your publish logic would look something like:

Set<Id> ids = new Set<Id>();
// populate somehow
EventBus.publish(new MyEvent__e(
    Ids__c = String.join(new List<Id>(ids), '\n')
    //, any other state you need to save

Then your subscriber logic would look something like:

Set<Id> ids = new Set<Id>();
for (MyEvent__e event : events)

List<User> records = [
    SELECT (SELECT Id FROM SomeChildren__r)
    FROM User WHERE Id IN :ids
// calculate rollups
update records;
  • I'm afraid that scheduled rollup isn't an option, because I really need this information right after the custom object's trigger is run. "Right after" might not be the proper expression, but it really is a short time (enough to make a scheduled process inviable, unless what you meant was to schedule the process to run after the trigger runs). Commented Jul 18, 2017 at 19:12

You must log in to answer this question.

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