I am trying to understand how the real-time mode of the Rollup Helper app works behind the scenes. I am looking for ways this can be achieved with, not necessarily how the developers built this particular app.

The documentation says that the app runs asynchronously, but Apex is nowhere near real-time when executed asynchronously. So I thought maybe somehow Heroku is involved. But then I read that the app is native and performs all its calculations on the platform. So I assume that means Heroku is not used.

So the question is, can real-time calculations be done in Salesforce asynchronously?

  • 3
    I'm voting to close this question as off-topic because it's a managed package and only the provider of the app will have a precise answer of how things work under the hood. – Boris Bachovski Apr 1 '16 at 2:02
  • I was thinking maybe someone knew how this could be done on the platform. It doesn't have to be exactly how the devs did it. I will edit the question to make it less app-centric. – Mossi Apr 1 '16 at 2:07

Asynchronous code will run in real time if the resources are available. For small processes in orgs that are not terribly busy write-wise, you may actually experience real-time performance for most edits. Once you start moving more data, it gets less real-time. For the day-to-day, "edit a record and be done with it" type orgs, asynchronous code will probably run even before the record has a chance to load on the page. You can try this out in a developer org by writing a simple trigger that just calls a future method, and have that future method perform some trivial update on the record. You'll usually see the change by the time the screen reloads.

Also, Salesforce tends to reorganize smaller requests so they run ahead of larger requests (I don't know the specifics of how they know this, but I know it tends to work well). If you have a lot of integrations and API calls that are writing data, the roll-up summary app (or any other asynchronous app) will get worse than real-time performance. This is typically rare for "small" (less than 500 users or so) orgs without any integrations, but may be incredibly common for larger orgs (more than 500 users) that also have a lot of integrations running.

Example Code:

public class AsyncUpdate {
    @future public static void updateIndustry(Id[] recordIds) {
        Account[] records = [SELECT Id FROM Account WHERE Id IN :recordIds FOR UPDATE];
        for(Account record: records) {
            record.Industry = 'Technology';
        update records;

trigger AsyncIndustryUpdate on Account (after insert, after update) {
    if(System.isFuture()) {
    AsyncUpdate.updateIndustry(new List<Id>(Trigger.newMap.keySet()));

If you try this code in a sandbox that isn't very busy, or a dev org, you'll notice that the update occurs so quickly that it may as well be real-time, but if you use the data loader, it'll run slower the larger the batch size is.

As the other answer also states, most intelligent code is designed to use some minimal amount of resources in real-time and defer larger requests to asynchronous code. This lets most of the data update in real-time without bogging down triggers.

  • Thanks. I didn't know that smaller jobs are run first. I'm assuming that's one feature of the Flex Queue. – Mossi Apr 1 '16 at 22:55
  • Marking as answer because it addresses my main question which was, can we run on-demand real-time tasks asynchronously in Apex. To sum it up we can achieve near real-time performance if the async job is small and the org is not too busy. Otherwise it is not possible (or at least it will be non-deterministic). – Mossi Apr 3 '16 at 19:15

The short answer is no. The name itself "asynchronous" tells you that it's not occurring at the same time. It might be near real-time, but you will never get real-time results.

I'm not exactly sure how it's working under the hood, also the documentation might be out of whack, but how I see it working is that there are 2 processes - synchronous and asynchronous. Depending on the total number of records, the logic runs one or the other. If you were to run that tool on a large number of records, I bet that it will not happen in real-time.

You should be seeking the long answer with more precise explanation directly from the vendor.

  • 2
    Asynchronous just means it runs after the current context. I've seen orgs where asynchronous code is executed in real-time most of the time. It really depends on how busy your database is in terms of writes (including integrations, etc). In fact, I wrote some example code that does run in real-time in my dev org, included in my answer. That said, I do agree that many developers probably make hybrid code that choose async or sync based on amount of data returned or trigger size. – sfdcfox Apr 1 '16 at 3:27
  • I have used the hybrid method in the past. It's good but with large datasets it takes some time to finish executing. Based on my 7 years of SF experience and the 2 answers thus far I think I can conclude that this is just a trigger based system (which it is) that uses Apex asynchronously. I thought maybe there's another way of running tasks on-demand in real-time in Apex, but I guess not :) – Mossi Apr 1 '16 at 23:02

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.