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)
ids.addAll((List<Id>)event.Ids__c.split('\n'));
List<User> records = [
SELECT (SELECT Id FROM SomeChildren__r)
FROM User WHERE Id IN :ids
];
// calculate rollups
update records;