Saturday, March 11, 2017

How to pass parameters from JavaScript to Controller in Salesforce

VisualForce Page

<apex:page>
  <apex:form>
    <apex:pageblock>
   <select id="dropDownId">
   <apex:commandButton value="Update" onclick="validate();return false;" />
 </apex:pageblock>

  <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="" />
    </apex:actionFunction>
  </apex:form>
</apex:page>

<script>
  funtion validate(dropDownId )
  {
    //Some processing here
  updateRecords(param1 value,param2 value,param3 value);
  }

</script>

Apex Controller

public class MyController
{
   public MyController()
   {
 
   }
 
   public pagereference performUpdate()
    {
     System.debug('..entered...performUpdate..');  
     String selDropdownVal=Apexpages.currentPage().getParameters().get('selStatus');
     String tableIdtoRender = Apexpages.currentPage().getParameters().get('renderTabId');
     String phone = Apexpages.currentPage().getParameters().get('phone');
     System.debug('..selDropdownVal...'+selDropdownVal+'..'+tableIdtoRender+'..'+phone);
   }

}

No comments:

Post a Comment