8 votes
Accepted

Why would a future method not show up in debug logs?

Future methods, once called, are only temporary until a database commit occurs. If an operation causes a partial or total rollback, this will include the future method calls, as well as any emails ...
  • 445k
6 votes

Avoid making 2 callouts for the same record

You can consider a "Status" custom field to keep track of the callout status: When callout is initiated, update Status to "Initiated" When the callout finishes, reset the custom ...
5 votes
Accepted

Mutation of Finalizer state

The reason why the documentation calls this out is that other types of Apex do not behave this way. public class QueueableFun implements Queueable { public Integer counter = 0; public void execute(...
  • 445k
5 votes

Mutation of Finalizer state

Fundamentally this is letting the developer know that if they have a class that implements both Queueable and Finalizer, where the Queueable "attaches" itself as its own finalizer, any state ...
  • 28.7k
4 votes
Accepted

Question for confirmation: Callout from Trigger using Platform Events

Platform Event Triggers also can't make callouts, so you'd still need a Future or Queueable method. Note that asynchronous methods are still called in order of being queued, so you don't really need ...
  • 445k
3 votes
Accepted

Batch Apex: class executed multiple times at once?

By default, Batchable Apex processes the results from the start method in batches of 200. Presuming you're saying that you create one campaign in the execute method, then you would indeed have five ...
  • 445k
3 votes
Accepted

LWC Async Function Returning Early

Why is the async method forcing a return without hitting any return line? That's the default behavior of async function: an async function always returns a Promise which will be resolved with the ...
  • 4,371
3 votes
Accepted

Does Platform Event / CDC uses same Async queue as Queueable/ Future?

You'll see that AsyncApexJob lists out what mechanisms use it Represents an individual Apex sharing recalculation job, a batch Apex job, a method with the future annotation, or a job that implements ...
3 votes

Does Platform Event / CDC uses same Async queue as Queueable/ Future?

Does CDC/Platform Event uses the same Async Queue which System.enqueueJob (Queueable) uses? No. Platform Events are not actually async executions; they are essentially synchronous executions in a ...
  • 28.7k
3 votes
Accepted

Promises in Apex?

There isn't a native equivalent of a Promise in Apex, but since you can make asynchronous calls, you can build a Promise-like functionality on top of that. One example of such a library is this one ...
  • 1,575
3 votes
Accepted

Avoid making 2 callouts for the same record

I would handle this with platform cache. Your invocable Apex should do the following high-level steps: define a cachebuilder class. See (https://github.com/trailheadapps/apex-recipes/blob/main/force-...
  • 7,038
2 votes

Why Queueable came into the picture

Queueables consume daily async executions from your limits somewhat like Batches do, but: You can only have 5 batches executing at the same time You can only have a further 100 batches queued for ...
  • 28.7k
2 votes

Avoid making 2 callouts for the same record

Steps: Create a custom field "Is Awaiting Response" (IsAwaitingResponse__c) (or whatever name you prefer). Create a validation rule - Formula=IsAwaitingResponse__c, ErrorMessage=Please wait ...
2 votes

Avoid making 2 callouts for the same record

The apex action invoked by the flow will be triggered synchronously, so at that point you can control for when it chooses to run the asynchronous method. In the invocable method you can log each ...
2 votes

Promises in Apex?

Probably the best you can do is persist the data from your callouts into a new object. Or if you are already working with one, persist the callout state there. Then you can add a section in your ...
  • 144k
2 votes

AsyncApex Scenarios

Correct. Correct. In addition, you can also pass collections of primitives. Correct. Note that you're limited to just one call, rather than the 50 you'd get in synchronous code. Incorrect. You are ...
  • 445k
2 votes
Accepted

How to make a batch class synchronous?

Batchable logic are just normal methods. You can emulate Database.executeBatch using something like this: public static void executeBatchSync(Database.Batchable<Object> batch, Type iterableType, ...
  • 445k
1 vote

Faster way for deleting millions of records

The fastest way would be to use an external API, which you could parallelize quite easily (but be aware of concurrent limits). As far as speeding up the batch, it won't go any faster than asynchronous ...
  • 445k
1 vote
Accepted

WebService returned a SOAP Fault: INVALID_SESSION_ID: This session is not valid for use with the API (async job)

For me this have resolved the issue: Go to the user's profile (in my case System Administrator) -> Edit -> set Session Security Level Required at Login to None -> Save. Somehow, if it is High ...
1 vote
Accepted

AsyncApexJob returning two records for one executed instance of batch

One way to gain insight is to add additional fields to your query on AsyncApexJob. These fields are available in the Object Reference for this object SELECT Id, JobType, ParentJob.Name, ExtendedStatus ...
  • 63.8k
1 vote

Best practice for async apex classes (Queueable, Batchable) in relation to service classes

My practice which is not bullet-proof and subject to better alternatives. If it is a Schedulable class with no call to a batchable (or calls a configurable batchable) xxxSchedulable If it is a ...
  • 63.8k
1 vote

Best practice for async apex classes (Queueable, Batchable) in relation to service classes

This is more an opinion questions so what I share here is an opinion, which may or may not work for you/others. We came to realize that in Salesforce due to nature of platform, smaller classes are ...
  • 1,650
1 vote
Accepted

Metadata cannot be deployed from within a test

Just use dependency injection wherever you query for the metadata to consume it. The simplest form looks something like below: public with sharing class MyService { @TestVisible static List<...
  • 144k
1 vote

Promises in Apex?

For up to three callouts specifically, you can use continuations. This works for Visualforce, Aura, and LWC. Obviously, this won't work for triggers and such. If you want to do this in asynchronous ...
  • 445k
1 vote
Accepted

I am getting FATAL_ERROR System.QueryException: unexpected token: BM_DPM_Date__c

You forgot a space just before WHERE. So it should be: 'FROM ' + queryObjectAPIName + ' WHERE BM_DPM_Date__c
1 vote
Accepted

How do I use batch apex if my method is creating over 40000 records

You can create the counter values as an array and return that from the start method (this being the less commonly used variant of start): public System.Iterable start(Database.BatchableContext jobId) {...
  • 131k
1 vote

Best architecture solution for Mixed DML Exceptions inside a Batch

Interfaces can be combined on a single class. public class ServiceClass implements Database.Batchable<sObject>, Queueable { public void execute(Database.BatchableContext context) { // ... ...
  • 445k
1 vote

Question for confirmation: Callout from Trigger using Platform Events

You can achieve this now with Platform Event Triggered flows. Once you publish a platform event. You can configure and flow to listen to this and then from the Flow configure it to call an Apex Action....
1 vote

DML Error on new Asynchronous Record-Triggered Flow

What you are looking for is an asynchronous callout action from record triggered flow. As the name suggests it's a "record triggered" flow. Since Salesforce does not allow callouts from ...
1 vote

DML Error on new Asynchronous Record-Triggered Flow

As you mentioned the Flow is "Record-Triggered Flow" so it seems that the whole transaction starts with the Case DML. I am assuming your @InvocableMethod is not calling any @future method ...

Only top scored, non community-wiki answers of a minimum length are eligible