I'm trying to pass a variable from a javascript inside a VF page to a varibale in the Apex Controller.

The VF page code is:

<apex:page controller="uploadDataTosObject" apiVersion="36.0"> 
            function setVal(result)
                document.getElementById("{!$Component.hdnField}").value =result;
        <apex:inputHidden id="hdnField" value="{!myblob}" />
        <apex:commandButton value="Post Page" action="{!post}" />
    <script src="https://cdnjs.cloudflare.com/ajax/libs/es5-shim/4.5.7/es5-shim.js">
   <script src="https://cdnjs.cloudflare.com/ajax/libs/xlsx/0.8.0/jszip.js">    </script>
   <script src="https://cdnjs.cloudflare.com/ajax/libs/xlsx/0.8.0/xlsx.js"></script>
            function to_csv(workbook) {
                var result = [];
                workbook.SheetNames.forEach(function(sheetName) {
                    var csv = X.utils.sheet_to_csv(workbook.Sheets[sheetName]);
                    if(csv.length > 0){
                        result.push("SHEET: " + sheetName);
                output = setval(result.join("\n"));
                return result.join("\n");

this is the VF controller:

public with sharing class uploadDataTosObject {       
    public String myblob {get; set;}        
    public void post(){

I need to assaign "result.join("\n")" to the variable "myblob" inside the controller. Now I'm trying to use an "apex:inputhidden", but the System.debug shows "undefined" in the Logs. How can I assign the variable "result.join()" to "myblol"?

  • 1
    You'll have to assign it to a string. Something in your controller like public void setContent(String value) { myBlob = Blob.valueOf(value); }. Then bind your inputHidden to content. – Adrian Larson Sep 30 '16 at 13:28

I'm not able to test if this works currently, but here's what I expect you need:


<apex:page controller="MyClass">
    <apex:inputHidden value="{!content}" ...>


public MyClass
    public Blob myBlob { get; private set; }
    public String content
        set { myBlob = Blob.valueOf(value); }
| improve this answer | |

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.