I am using an action function which seems to work, but I also need a javascript callback. When I specify the oncomplete attribute with a javascript invocation, I get an error:

Formula Expression is required on the action attributes.

What am I doing wrong?



<apex:form >
<apex:actionfunction name="af_submitFile" action="{!uploadFile}" oncomplete="uploadCallback()">
    <apex:param name="fileName" value="" assignTo="{!fileName}"/>
    <apex:param name="fileBinaryData" value="" assignTo="{!fileBinaryData}"/>
<script type="text/javascript">
var fileName = 'test';
var fileBinaryData = 'test';

var uploadCallback = function(result, event){
        //callback here

af_submitFile(fileName, fileBinaryData);

Apex Controller:

global with sharing class UploadHandler {
    public string fileName {get;set;}
    public string fileBinaryData {get;set;}

    public String uploadFile(){
        //do stuff
        return 'success';

  • You're getting a compile error? That compiles fine for me. – Adrian Larson Aug 12 '16 at 1:25
  • Not a compile error. I think the action function af_submitFile is running fine. It's only when I specify the oncomplete callback parameter in the action function definition do I get the error "Formula Expression is required on the action attributes" – user1813867 Aug 12 '16 at 1:30
  • 1
    But where do you get the error? It sounds like a compile error. Please edit your post to include a screenshot if possible. – Adrian Larson Aug 12 '16 at 1:32

It is throwing error because you are trying to return a string from the action call (uploadFile method). Action method should return PageReference (you can return null as PageReference if you don't want to move to another page) for if you don't want to return anything then make it void.

  • I see - in my case I actually want to return a value (the ID of the newly inserted file blob). Can I somehow get a value back to the javascript callback? – user1813867 Aug 12 '16 at 17:52
  • Nevermind - I think I found the answer to my question here: blog.jeffdouglas.com/2011/01/17/… – user1813867 Aug 12 '16 at 17:56

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.