1

I have this simple JS function implementation within my VF page:

<script>
 function toSend(){
   var myField;
   //Received myField value with some code//

   callingActionFunction(myField);

   //some more coding//
  }
</script>

<apex:actionFunction name="callingActionFunction" action="{!getFieldID}" immediate="true" rendered="false">
   <apex:param assignTo="{!agentObjID}" name="myField" value="myField"/>
</apex:actionFunction>

My controller class:

public String agentObjID {get; set;}

public void getFieldID(){
  //SOQL to query based on the value: agentObjID 
  //but I am not receiving anything from my VF page.
}

But this above implementation is not seeming to work. All I am trying to do is: get the myField value in the VF's JS function and pass it to my controller class (I have get/set variable) and retrieve some record(s) based on that value. Can someone suggest me if I am doing it wrong or missing something simple or, my approach itself is invalid?

1
  • Is it because the actionFunction is not being rendered and can't be called as a result? What happens if you remove the rendered="false" from the apex:actionFunction? – Instread Oct 15 '20 at 0:32
0

Try to explore PageReference on the method to view string parameters and values for a page inside the method use

public PageReference getFieldID(){
  //SOQL to query based on the value: agentObjID 
}

Or

    <apex:actionFunction name="callingActionFunction" action="{!getFieldID}" immediate="true" rendered="false">
         <apex:param name="myField" value="myField"/>
     </apex:actionFunction>

        public PageReference getFieldID(){
          //SOQL to query based on the value: agentObjID 
          string agentObjID = Apexpages.currentPage().getParameters().get('myField');
        }

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.