Salesforce Stack Exchange is a question and answer site for Salesforce administrators, implementation experts, developers and anybody in-between. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I know a specific org can enqueue up to 250,000 async jobs per 24h period in an org.

My app uses a few Queueable jobs on nearly every user transaction to send Usage Metrics to another server so this sums up. It's not a problem if some of them fail or don't run because the 24.h limit is reached.

But how can I decrease the risk for other async jobs?

  • Enqueue myself at night (Can I keep my jobs in pending?)
  • Use Flex Queue priorities (Is this already GA?)
share|improve this question

This is just a thought, but say you have Accounts, Contacts, Leads(whatever your objects are) and everytime one of these records qualify for changes (whatever that may be) you can create a new record in a custom object.

Let's call the object something like Service Transactions ..", so now rather than having your queueable fire every single time an Account,Contact .. etc qualifies for a queueable job you will actually just be inserting a new record into the Service Transaction table, now when you insert the record into the service transaction you will essentially only need the ID, and maybe a success or failure flag.

By inserting the ID with that Service Transaction you will now be able to build the data that you need to send out.

You can schedule the queueable(I think, you may have to get creative) to fire whenever you want, maybe end of day or middle of the night. This is just an idea..

If there is a concern about the strain that will be put on the org by the async jobs this cannot be real time.

share|improve this answer
    
I was thinking the same but custom settings. The obvious solution to reduce volume is batching the callouts. Can't upvote for a few mor minutes yet. – Adrian Larson 11 hours ago
1  
A Scheduleable batch job (or a batch class scheduled by some other means) would seem like a better candidate for this than Queueable, since it will scale better with more transactions. Depending on the API, you may even be able to batch the callouts with more than one record at a time. – IllusiveBrian 11 hours ago
    
@IllusiveBrian I think he's trying to chain jobs which you can't do from a batch, but I was thinking that also – EricSSH 10 hours ago
    
Who says you can't chain batches? – Adrian Larson 10 hours ago
1  
You can straight up put Database.executeBatch(this) in the finish method. You probably want some mechanism to turn it off though if you want any hope of a sane testing pattern. I also sometimes use system.scheduleBatch(this, 15) as it's easier to pull off than "suicide scheduling" in my limited attempts so far. – Adrian Larson 10 hours ago

For your particular case, EricSSH's answer is probably the best option. However, here are some answers for your question:

  1. You can query the ApexAsyncJob object to query asynchronous operations, though I cannot seem to find a way to specify 24 hours in SOQL. Additionally, this will run into the 50000 row limit on SOQL results.
  2. Eventually, the limits class appears to be slated to have getAsyncCalls and getLimitAsyncCalls functions which will return the number of async calls made in the last 24 hours and the organization's limit on async calls in 24 hours, assuming they follow the naming convention of the rest of the class.
share|improve this answer
    
+1 one to that because there is always more than one way, if you can quantify how many async jobs will actually run you may be able to also create a buffer so you can stop your server metrics from sending by using Brians idea with the limits. Granted I don't think it would be a great idea to create an artificial buffer but who knows – EricSSH 7 hours ago

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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