+ Start a Discussion
Heiko LHeiko L 

Call APEX from Visual Workflow

When trying to call an APEX class from any flow in my DE org I get an error message:

A fault occurred while executing your script:
Data Not Available: The data you were trying to access could not be found. It may be due to another user deleting the data or a system error. If you know the data is not deleted but cannot access it, please look at our support page.

I'm actually getting the error whenever a flow is trying to invoke APEX, even when I use an example that was posted on a salesforce.com blog. Does nybody have any ideas?
Scott McClungScott McClung
Usually that error means you're trying to reference a record that doesn't exist.  Do you have any hard coded record id's in your code?
Posting your code may help with troubleshooting.
Heiko LHeiko L
Thanks, Scott. But the code does not reference any data. Plus, I have the same thing happening when I use the samples from this blogpost: https://developer.salesforce.com/blogs/developer-relations/2012/03/visual-workflow-converting-leads-with-an-apex-plugin.html I know the samples have worked for me in the past in other orgs so I'm pretty sure it's not a data problem. Last but not least, I'm an admin in that DE Org so I should have access to everything.
Hi Heiko,

I am not sure what the issue could be, but I have done this in my org. Here is an example of my Class which is referenced from my flow. If you follow this you should get the flow and apex working..


global class flowExceedNameLength implements Process.Plugin{


// Main Code

       global Process.PluginResult invoke(Process.PluginRequest request){


              //This retrieves the input from your flow

String salu = (String) request.inputParameters.get('sal');

              String fname = (String) request.inputParameters.get('firstname');

              String lname = (String) request.inputParameters.get('lastname');

              system.debug('####: ' + salu + ' '+fname+' '+lname);


              //Your logic ie what you want the code to do

              integer d = VisualProcessManager_Maintenance_v1.exceedNameLength(salu, fname, lname);          

              // return to flow

              Map<string, object> rtnValue = new Map<string, object>();

              rtnValue.put('exceedlen', d);


              // Return result

              return new Process.PluginResult(rtnValue); 



//This is a must this defines all the inputs and output for apex plugin. You flow may not reference the class correctly if you do not define this.

       global Process.PluginDescribeResult describe() { 

        Process.PluginDescribeResult result = new Process.PluginDescribeResult();

        result.inputParameters = new List<Process.PluginDescribeResult.InputParameter>{

               new Process.PluginDescribeResult.InputParameter('sal',

                   Process.PluginDescribeResult.ParameterType.STRING, true),

               new Process.PluginDescribeResult.InputParameter('firstname',

                   Process.PluginDescribeResult.ParameterType.STRING, true),

               new Process.PluginDescribeResult.InputParameter('lastname',

                   Process.PluginDescribeResult.ParameterType.STRING, true)


        result.outputParameters = new List<Process.PluginDescribeResult.OutputParameter>{

                     new Process.PluginDescribeResult.OutputParameter('exceedlen',



        return result;



Hope this helps

Heiko LHeiko L
Hi RepsG!

Thank you for your response and I agree, your code should work and it looks very similar to my code. And here's what I've just done:
  • copy and paste your code into a new Apex class (I had to modify one line since I don't have access to the exceedNameLength method; but I just replaced it with a hard coded number)
  • create a new VWF that consists of 3 elements:
    • A screen taking in the data for the Apex class (Salutation, First Name and Last Name
    • the call to your Apex class
    • A screen displaying the output of your Apex class (I would've expected to see my number)
Unfortunately, I do get the exact same error message. Seems like something isn't setup right in my org or maybe I've discovered a bug?!?

Thanks again,

Heiko LHeiko L
And I just tried the same thing in a sandbox that I have access to and it worked fine ... :-(
Strange, It works in Sandbox environment but not the DE org? Sound like there is some sort of restriction on the DE org. May be worth calling support to get them to investigate it.

On the brightside, it does work :-D
Heiko LHeiko L
Thanks RepsG! Yes, on the bright side, I wasn't making a dumb mistake. On the not so bright side, I've tried to log a ticket and it keeps me in a loop between the "Contact Support" and the login page. Oh what fun ...
Marty C.Marty C.
Hello, Heiko, are you trying to log the case from your DE org? I don't believe this is possible, as there is no SLA for DE org users. You will need to log the case from a customer org or via the Partner Portal (if you're a Salesforce partner). The unfortunate reality may be that you need to sign up for a new DE org.
Heiko Leibenath 7Heiko Leibenath 7
Thanks, Marty! I've actually logged a ticket with the account I have for my employer. I might sign up for a new DE just to check if it works in that org. Thanks again.
Heiko LHeiko L
Turns out I found a bug. I've had Namespace enabled in that org and somehow that's conflicting with VWF calling Apex ... Go figure. The've logged a known issue for this.