1

Inside a future method we are inserting some records and we've come across a problem when Apex takes about 4.5 seconds delay between 'Executes all before triggers' and 'Runs most system validation steps again' according to the docs

This is what the log looks like:

    ...
    08:54:58.402 (7402783770)|CUMULATIVE_LIMIT_USAGE_END
    
    08:54:58.29 (7407403780)|CODE_UNIT_FINISHED|ABC_QuoteLineItemTrigger on ABC_QuoteLineItem trigger event BeforeInsert|__sfdc_trigger/ABC_QuoteLineItemTrigger
    08:55:02.812 (11812110635)|CODE_UNIT_STARTED|[EXTERNAL]|Validation:ABC_QuoteLineItem:new
    08:55:02.812 (11812242796)|VALIDATION_RULE|03d1v000000BPxV|ABC_QLI_BlockNegativePrice
    08:55:02.812 (11813121538)|VALIDATION_FORMULA| ... FORMULA GOES HERE ...
    08:55:02.812 (11813210093)|VALIDATION_PASS
    ...

Note the difference in timestamps:

  • 08:54:58.29
  • 08:55:02.812

I was under the impression that Apex shouldn't take pauses like this. Is this something unique to future methods?

What happens inside this 4.5 seconds and how do I remove this wait time?

3
  • 3
    Is this something you are seeing consistently, or just in this example? Async processing runs when resource is available. It might have been that the org instance was under load and you happened to see this apparent pause because of it. Remember that multi-tenant arrangement...
    – Phil W
    Commented May 2 at 13:56
  • This happens only occasionaly. This was my suspicion too. My understanding was that once it's in the queue and it's this transaction's turn for execution it can not be paused mid way. Certainly not in the middle of the triggers and validation rules. I couldn't find in the docs any reference to this behaviour. Is there a page about it? Commented May 2 at 16:02
  • 1
    Interactive (I.e. synchronous) transactions always get priority, so if the instance is flooded with these it would be natural for async transactions to be effectively starved of resource for a period. There is literally nothing you can do to control this. It is a fact of life on the Salesforce platform (unless your org is big enough to warrant its own instance).
    – Phil W
    Commented May 2 at 16:12

0

You must log in to answer this question.

Browse other questions tagged .