Questions tagged [future]

A future method runs in the background, asynchronously. You can call a future method for executing long-running operations, such as callouts to external Web services or any operation you’d like to run in its own thread, on its own time.

Filter by
Sorted by
Tagged with
38
votes
3answers
13k views

Is there any way of confirming that an @future method has been called/queued in a test class?

I have a Controller (FooController) which calls an @future method (bar()) belonging to another class (FooServices). Ideally in my test class for this Controller (FooControllerTest) I only want to ...
27
votes
2answers
9k views

How can I determine how many future calls have been executed in 24 hours?

I just ran into a huge gotcha in Salesforce: the 24 hr limit on # of future calls - cf. http://www.sundoginteractive.com/index.php?/sunblog/posts/governor-limit-gotchas-part-1-the-future-call/. I ...
26
votes
4answers
24k views

Can Queueable solve "Future method cannot be called from a future or batch method"?

I have code that must be called as @future as it requires all the resources one can get. The only problem is that in 1% of the cases this code is called from a Batch and therefore fails with System....
26
votes
5answers
34k views

Calling future method from Batch

I have a requirement where a future method need to be called from batch apex ,I came across various articles stating that a future method could not be called from the batch. Is there any alternate ...
22
votes
4answers
3k views

@future runs in test without Test.stopTest() - Can that be?

For the last years I expected all async Apex means not to run in tests when there is no Test.stopTest() in my test code. But now I have a test without this call and a future method is called. I ...
21
votes
2answers
903 views

@Future at risk for race conditions?

Question If I invoke an @future method from a trigger that is performing a calculation based on data that is being committed in the trigger am I at a risk for a race condition? Background We're ...
18
votes
3answers
5k views

Knowing if a future call is allowed

I'm having an issue where we have some code that can be called anywhere and then it makes an @future call to log a message to an external system. The problem is if this method is called (either ...
17
votes
1answer
10k views

Difference between Queueable apex and future method

I understand that you could pass collection of Sobjects to Queueable apex classes but not to future methods where we're restricted to only primitive collections. The reason it's not done for future ...
15
votes
3answers
15k views

Future Method calling Another Future Method

I have two future methods f1 & f2. Each of them takes long time to process as such I have annotated them as @future. There is a scenario in which I need to make a callout to f2 from f1. Any ...
15
votes
3answers
1k views

Batch Apex in AppExchange package and orgs with related triggers that call @Future methods

Here's the problem: when an org has a trigger that calls an @Future method, any batch Apex that fires that trigger will fail, since you cannot call an @Future method from an @Future method OR from ...
13
votes
3answers
2k views

Use JSON serialization to get around parameter limitations for future methods?

Future methods can only take primitives or collections of primitives as parameters. To get around this you could serialize Sobjects (or classes) to a string and then deserialize them in the future ...
12
votes
2answers
2k views

Does queueing a future method count as DML?

We need to implement the following pattern at my org: callout to external data source if that callout takes too long (according to some configurable threshold), log an error (ie do some DML) if that ...
12
votes
4answers
4k views

How can you avoid hitting 24-hour limits on emails and future calls?

I realize there are plenty of ways to try to avoid hitting limits in the first place, but when it comes to features with 24 hour limit plans, how can you know if you're getting close to them? And ...
11
votes
3answers
3k views

Avoiding use of future calls in triggers?

I have some code I'd like to change in a trigger. The issue is that there is a field that is being updated with a prefix plus the value of a field in the object that is an automatic number. The ...
11
votes
1answer
12k views

Is it possible to make Remote Action Asynchronous?

I have a Remote action call from my Visualforce Page. Visualforce.remoting.Manager.invokeAction( '{!$RemoteAction.PartnerPrimeSubController.calculatePartnerPrimeSub}', ...
11
votes
3answers
4k views

Why is Map<Id, Set<Id>> an unsupported parameter type in future methods?

I am trying to create some junction records via callout (in this case, SkillUser records). Since I am doing so from a trigger, I need to use a @future annotated method. The Apex Developer Guide states ...
11
votes
1answer
4k views

Chaining Scheduled Apex to process callouts every 30 seconds

We wanted to create an outbound message queue system that would process requests individually and in order to any external web service. The frequency that these requests should be processed is ...
10
votes
2answers
7k views

How to work around the 100 callout limitation?

We need to have the ability to make more than 2999 callouts to a REST service. Currently, we are getting a raised exception when the number of callouts is more than current limit for callouts. Thus, ...
10
votes
4answers
7k views

How far in the future are @future annotated methods executed?

What is the maximum estimated time before execution of an @future annotated method starts, after the call to the function is made? Is this in the order of seconds? Or can it take up to minutes before ...
10
votes
2answers
763 views

Guarantee only a single asynchronous job runs at a time

This is a bit of an odd one. We are interacting with an external system that does not support concurrency due to a bug which they are struggling to fix. We perform a HTTP callout, the callout takes ...
10
votes
2answers
8k views

First error: [UNKNOWN_EXCEPTION] ConcurrentPerOrgLongTxn Limit exceeded

We are currently facing a Salesforce platform error I have never seen before; First error: [UNKNOWN_EXCEPTION] ConcurrentPerOrgLongTxn Limit exceeded This happens both when logging into the API ...
10
votes
4answers
3k views

Chaining @future methods

Is there any way/workaround at all to call a future method immediately from another future event? If not what's the fastest way to call my future method indirectly? I basically have a 3rd party ...
10
votes
1answer
794 views

Are @future methods ignored in @TestSetup blocks?

Ok, this is going to become a quite long question. The main goal is to document strange platform behavior and maybe learn more why this happens. It all started with that test which failed because ...
10
votes
2answers
2k views

GetContentAsPDF from Batch Apex and Trigger fails with new Update

[Salesforce Update] The critical update named “PageReference getContent() and getContentAsPDF() Methods Treated as Callouts” was scheduled for auto-activation in Winter ’16. To allow for planning ...
9
votes
3answers
9k views

how to test a future method which makes callouts?

I am practising the Integration workbook provided by salesforce. In tutorial#2 there's a class which makes future callouts to a Heroku app.This class is called by an after update trigger. Callout ...
9
votes
1answer
9k views

Future method cannot be called from a future or batch method, Case Trigger with Salesforce for Social

I get the following inside a Case Trigger when I try to call a future method: System.AsyncException: Future method cannot be called from a future or batch method So far this exception ONLY occurs ...
8
votes
2answers
12k views

Error: Future method cannot be called from a future or batch class [closed]

My requirement is getting latitude longitude from google map for that i wrote trigger and used @future callouts. now i need to run batch class to update contact records but contacts not updating ...
8
votes
2answers
7k views

What is the best approach to call a webservice from SFDC?

Objective: When an Account is created in Salesforce I need to call a SAP webservice and create a customer in SAP. What would be best approach? To call the SAP webservice from the Account trigger ...
8
votes
2answers
13k views

Callout Limits for future methods and queueable apex

I'm aware from the docs that "A single Apex transaction can make a maximum of 100 callouts to an HTTP request or an API call." Is anyone aware if that limit is higher in a future methods or ...
8
votes
1answer
2k views

Future vs batch

I need to make asynch call from trigger. Records are comming (1 or 1000 at once) each minute and I need to process them from trigger asynchronously. As I see limits for future and batch jobs are the ...
8
votes
1answer
1k views

Test execution order issues with Queueable and @future method

Test code: * Test.startTest(); * System.enqueueJob(new MyJob()); * Test.stopTest(); * System.debug('Quering record for assertion'); Expected Queueable job execution: * Job Start * Query records * ...
8
votes
1answer
1k views

Calling a Callout via @future still gives uncommitted work pending error

Class A is simple page controller. It creates an instance of Class B. The user can click a button on a VF page to invoke a pagereference method in Class A that will invoke various methods in class B, ...
8
votes
2answers
482 views

Callout from a future event

I have a managed app that does a callout (REST API POST) on Account save. The managed app is developed by a 3rd party that we have no control of. The callout creates a future event which gets an id ...
7
votes
2answers
5k views

Queueable - Callout not allowed from this future method

I am using a queueable class to handle various date ranges that are then sent to a web service. Upon calling the queueable class I am receiving the following error: Callout not allowed from this ...
7
votes
1answer
10k views

Error: Future method cannot be called from a future or batch method

I have a managed packaged that I recently updated and it threw an error for a future method I have that sends information to a third party. The error I received was: Future method cannot be called ...
7
votes
2answers
12k views

Debug or view status of a @future method

Can I see the errors or debug messages my @future calls may be generating? How can I see if a @future method was executed at all? Details: I have a trigger which needs to update some User accounts in ...
7
votes
2answers
9k views

Getting current PageReference from Controller Extension in @future context

I'm attempting to get current pageReference for a VisualForce page (renderAs=pdf) that is being executed in @future context, but at the moment it is just returning a null. So I assume the problem is ...
7
votes
4answers
2k views

Parallel callouts in apex

On some user action, I am calling several different third party services in order to update data in salesforce. As these callouts are time consuming, I would like to execute them in parallel, and when ...
7
votes
2answers
12k views

Call Queueable from future method

I have a use-case where I need to execute some logic in async mode and I found that using Queueable Interface I can achieve that. But when I am trying to the use the Queuable Interface, some issues ...
7
votes
1answer
358 views

Is an AsyncApexJob record inserted immediately at the end of a transaction?

Is an AsyncApexJob record inserted immediately at the end of a transaction or is it possible that there is a delay between those two events? I couldn't find firm guarantee in the documentation on that....
7
votes
3answers
2k views

Can future execution start before the synchronous execution is completed

Is there a way for @future annotated method to start execution before the synchronous request which invokes it has completed. In other words, do I have some guarantees that the timing will look like ...
7
votes
1answer
1k views

@future and triggers

I want to do a bulk update of records in parallel, but Batch Apex doesn't permit this. I was wondering if the following solution would work: I have an SObject defined that holds a value for the ...
6
votes
3answers
12k views

Prevent trigger from running in single test

Ok so I have a fairly complex scenario I need to test... I have a Trigger on a MyObject__c that creates PermissionSetAssigments when MyObject__c is inserted. Because PS Assignments are system ...
6
votes
2answers
708 views

Queueable Apex consideratoins

This is more of a theoretical question and probably goes more to design and I hope I can do this justice. I have successfully coded in apex multiple triggers which make callouts using the @future (...
6
votes
2answers
11k views

You have uncommitted work pending. Please commit or rollback before calling out

i have written a future method here is source code @future(callout=true) public static void futureDownloadAttachment(Set<ID> documentsID){ List<SpringCM_Attachment__c> logs = [...
6
votes
1answer
5k views

Wait for Future Method execution before doing DML

Scenario : Before inserting a record I will check another System(REST call) and then decide(control) to insert or update in Trigger context. I have Trigger which does REST call inside future method. ...
6
votes
1answer
1k views

Why do debug logs not always work for a @future method?

I'm working on an Apex class that contains a method annotated with @future. Inside of the method I have a few system.debug statements I'm using to figure out why it's not working. The problem is -- if ...
6
votes
2answers
1k views

How to test @future methods with setup objects and avoid MIXED_DML_OPERATION

I’m in a situation where I have to use a future method to avoid MIXED_DML_OPERATION error. I have a trigger that runs after INSERT on USER and creates a custom object X. They are in 1:1 relation. ...
6
votes
1answer
5k views

Queueable Job limit hit when trigger is batched

I am trying to run a very simple trigger, in concept. The purpose of the trigger is to count some items simply, then update a field on two objects based on that number. At first, I attempted to ...
6
votes
2answers
1k views

Cannot deserialize JSON as abstract type?

While writing a class to help me manage @future jobs for a project, I stumbled onto an error message I can find very little help on. Cannot deserialize JSON as abstract type I used an interface ...

1
2 3 4 5
9