I need to be able to pass some javascript variables from the visualforce page over to my apex class. I'm able to do it with the record ID as I'm using the standard controller but having a hard time getting any Javascript variables to go through.

This is the Apex Class:

    public class RunSquarePaymentFlow {

    public Flow.Interview.Update_Square_Transaction squareFlow {get; set;}
    public String currentRecordId {get; set;}
    public String squareOrderId{get; set;}

    public RunSquarePaymentFlow(ApexPages.StandardController controller) {
        currentRecordId  = ApexPages.CurrentPage().getparameters().get('id');
        squareOrderId = ApexPages.CurrentPage().getParameters().get('orderId');


    public void start() {

        Map<String, Object> myMap = new Map<String, Object>();
        myMap.put('recordId', currentRecordId);
        myMap.put('OrderId', squareOrderId);
        squareFlow = new Flow.Interview.Update_Square_Transaction(myMap);


And here is the apex:param section of the visual force page:

    <apex:actionFunction name="RunSquarePaymentAction" action="{!start}" rerender="">
      <apex:param name="orderId" assignTo="{!squareOrderId}" value=""/>


var orderId;

I'm just trying to get the orderId javascript variable into the apex method so that it can be passed into my flow. If any one can point where I went wrong that would be swell.

  • where is your js function that calls RunSquarePaymentAction? can you share that too?
    – Mark Pond
    May 6 '20 at 23:50

Can you share everything between your script tags there?

You could use some jQuery that would set the value of a hiddenApex input that your controller can access the value of. You will need to explicitly set that value based on that hiddenApex input's ID, something like this:

<apex:inputHidden value="{!squareOrderId}" id="hiddenApex"  required="false" html-label="Square Order" html-data-label="Square Order"/>


var orderId;
//Some Code to set this var...


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.