Wednesday, January 4, 2017

How to pass parameters from JavaScript to Controller in Salesforce

If you want to send more than one parameter from javaScript to Apex controller in your class,no worries it can be done easily .Please follow the below snippet to achieve the same.

Sample VisualForce Page

   <select id="dropDownId"/>
   <apex:commandButton value="Update" onclick="validate();return false;" />
  <apex:actionFunction name="updateRecords" action="{!performUpdate}" 
                              reRender="resultPanel,errMsg" status="statusSaveTrip">
        <apex:param id="status" name="selStatus" value="" />
        <apex:param id="renerTabId" name="renderTabId" value="" />
        <apex:param id="phone" name="phone" value="" /> 

  function validate(dropDownId )
    //Some processing here
  updateRecords(param1 value,param2 value,param3 value);

Sample Apex Controller

public class SampleController
   public SampleController()
   public pagereference performUpdate()
     String selDropdownVal=Apexpages.currentPage().getParameters().get('selStatus');
     String tableIdtoRender = Apexpages.currentPage().getParameters().get('renderTabId');
     String phone = Apexpages.currentPage().getParameters().get('phone');

Thanks for visiting..hope this helps you!

No comments:

Post a Comment