function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
PM Modi YojanaPM Modi Yojana 

Does queuing a future method count as DML?


 
Hi all,

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 callout timed out on the remote server, try it again
Recognizing the potential for the dreaded "You have uncommitted work pending. Please commit or rollback before calling out." error, I put the error logging code in a future method, thus isolating the DML from the callouts. However, the error is still being thrown. I reduced the issue down to this pattern:
public static void foo() { Http http = new Http(); HttpRequest req = new Httprequest(); req.setEndpoint('https://test.salesforce.com'); //whatever endpoint req.setMethod('GET'); http.send(req); //works fine bar(); http.send(req); //throws calloutexception } @future public static void bar() { }
Am I correct to assume that calling a future method counts as a DML operation? Is there any documentation I'm missing somewhere?

For more information you can visit here https://bit.ly/2O1RwLF
 
AbhishekAbhishek (Salesforce Developers) 
It doesn't count as DML, however, queued asynchronous actions enter a queue to be executed after the present transaction.


You could use try/catch to actually catch the callout exception and then do your DML afterwards to record what the outcome was.



If what you really want is to log something before or between callouts, that remains logged even if you reach an uncaught exception, look into Platform Events as a way to initiate this. Platform Events do NOT roll back, and you can hang triggers or Process Builders off of them to ensure some log is created.




See Andrew Fawcett's Dreamforce talk on this topic: https://www.youtube.com/watch?v=yYeurYnasVc


Let me know if it helps you and close your query by marking it as the best answer so that it can help others in the future.

Thanks.
PM Modi YojanaPM Modi Yojana
It doesn't count as DML, however, queued asynchronous actions enter a queue to be executed after the present transaction.
https://bit.ly/2O1RwLF
UP Ration Card List (https://bit.ly/2O1RwLF
UP Ration Card List  (https://bit.ly/2O1RwLF)

You could use try/catch to actually catch the callout exception and then do your DML afterwards to record what the outcome was.

UP RATION CARD LIST (https://bit.ly/2O1RwLF
https://bit.ly/2O1RwLF
https://bit.ly/2O1RwLF
https://bit.ly/2O1RwLF

Malika Pathak 9Malika Pathak 9

Hi PM,

This question has been more conclusively answered here

https://salesforce.stackexchange.com/questions/203304/does-queueing-a-future-method-count-as-dml

If you find this helpful mark it as the best answer.

PM Modi YojanaPM Modi Yojana
Hi, if you want answer then  CLICK here yadav ko kabu kaise kare  (https://www.pmmodiyojana2020.com/2021/03/yadav-ko-kabu-kaise-kare.html) or
https://www.pmmodiyojana2020.com/2021/03/yadav-ko-kabu-kaise-kare.html
2.  Muslim ko kabu kaise kare (https://www.pmmodiyojana2020.com/2021/03/muslim-ko-kabu-kaise-kare.html)  or
https://www.pmmodiyojana2020.com/2021/03/muslim-ko-kabu-kaise-kare.html
3. Rajput ko kabu kaise kare (https://www.pmmodiyojana2020.com/2021/03/rajput-ko-kabu-kaise-kare.html) or
https://www.pmmodiyojana2020.com/2021/03/rajput-ko-kabu-kaise-kare.html

Please must click on links and watch answer