Activity Forums Salesforce® Discussions What is the use of apex param?

  • Shaharyar

    Member
    August 8, 2017 at 4:25 am

    <apex:param> tag is mainly used to pass values from JavaScript to an Apex controller, it can only be used with the following parent tags/The <apex:param> component can only be a child of the following components:.
    • <apex:actionFunction>
    • <apex:actionSupport>
    • <apex:commandLink>
    • <apex:outputLink>
    • <apex:outputText>
    • <flow:interview>

    1. One example can be seen as:

    #VisualForce Page:

    <apex:page controller="paramtest" docType="html-5.0">
    <apex:form>

    <apex:commandbutton action="{!testdirect}" reRender="test" value="Static value">
    <apex:param assignTo="{!value}" value="The static value that was set from vf page"/>
    </apex:commandbutton><br/>
    <input type="text" id="testinput"/>
    <input type="button" onclick="testinputJS()" value="Dynamic Value" class="btn"/>
    <apex:outputPanel id="test">
    <apex:outputText value="{!value}"/>
    </apex:outputPanel>
    <apex:actionFunction action="{!testinput}" name="passToController" rerender="test">
    <apex:param value="" name="inpval"/>
    </apex:actionFunction>
    </apex:form>
    <script>
    function testinputJS(){
    var str = document.getElementById('testinput').value;
    if(str.length >4){
    str= str.substring(0,4);
    }
    passToController(str);
    }
    </script>
    </apex:page>

    #Apex Class/Controller:

    public class paramtest {
    public string value { get; set;}

    public void testdirect(){
    system.debug(value);
    }
    public void testinput(){
    value = apexpages.currentPage().getParameters().get('inpval');
    system.debug(value);
    }
    }

     

     

     

     

  • shariq

    Member
    August 8, 2017 at 5:58 am

    Thanks Shaharyar,

    It helps a lot.

  • Parul

    Member
    September 15, 2018 at 4:54 pm

    <apex:param> tag is mainly used to pass values from JavaScript to an Apex controller.

     

    Thanks

Log In to reply.

Popular Salesforce Blogs

Popular Salesforce Videos