I'm trying to get some advanced architecture setup for my company, but I'm running into an issue with my design; looking for help.

I'm attempting to execute an API call from Flow, but I'm getting the dreaded CalloutException: You have uncommitted work pending. Please commit or rollback before calling out.. I know this means I need to put @Future on my call out, but I'm wondering if anyone knows of a way to put that function into the flow? Is there any element that would commit the work of my transaction?

The main reason I ask is I want to get the response of the call out into the flow - meaning I cannot use the future annotation as it prevents the response from being returned. If nothing else works I'm going to have to leverage the response (as an inserted record) to trigger a follow up flow, but this is a heavier design than I'd like and creates some security considerations.

I've attempted using a wait element, but it appears the method invoked is still considered part of the same transaction. I setup an absolute alert for 0.016777 hours (1 minute) after current time, but still receiving the error. I'm going to try a relative alert to see if that works.

TL;DR: I'm looking for a way to get Flow to commit work prior to a specific element. Is there a way to do this?

  • Does your flow have any screen elements? If so a screen should start a new transaction. – gorav Feb 1 '17 at 21:42
  • Also have you seen the spring17 external services beta? The example in the release notes seems like it's similar to your use case. releasenotes.docs.salesforce.com/en-us/spring17/release-notes/… – gorav Feb 1 '17 at 21:49
  • @gorav unfortunately, no screen elements - we want the entire process automated, so no user interactions. Thanks for the external services link. I'm not up-to-date on that feature, is that a beta for standard Salesforce or is one of their lightning connect services required? – zainogj Feb 1 '17 at 22:01
  • Not sure, just have it tucked away to explore once we get spring.17, kinda seems like it's standard but few things are these days. Will see if I can find docs on it. – gorav Feb 1 '17 at 22:28
  • cant we do sync callout instead of future callout, I have similar req but need to do Sync callout as I need response come into flow. please advise. – Murthy Alluri Feb 14 '17 at 20:29

There is nothing that can explicitly cause a commit in a way that gets rid of this error in live code. System.runAs prevents this error, but only for unit tests (because System.runAs only works in unit tests). You can use an InvocableMethod in a flow, and from there, kick off a future method, thereby splitting the transaction in two; the future method can safely perform the callout after the flow's current transaction completes and is committed.

public class DoCalloutFromFlow {
    @InvocableMethod(label='Do Callout', description='Performs a callout after the flow completes')
    public static void doCallout(Id[] params) {
    public static void futureCallout(Id[] params) {
        // Do your callouts here

Note: You can actually cause commits during a Visual Flow, as each screen element ends a transaction. However, when you're using any sort of Process Flow, you're already in DML-land and can't perform a callout.

  • Thanks @sfdcfox, that was my fear. Sounds like I'll have to redesign this to go into @future then store my response and trigger a follow-up flow to get what I want. lol at DML-land. – zainogj Feb 1 '17 at 15:47
  • @sfdcfox are you familiar w the flow external services beta? I haven't tested it yet, not sure about cost either. It seems to address something along these lines releasenotes.docs.salesforce.com/en-us/spring17/release-notes/… – gorav Feb 1 '17 at 22:37
  • @gorav That's cool stuff. Not sure if it would work anywhere, or just in Visual Flow, but it looks handy. – sfdcfox Feb 1 '17 at 23:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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