Activity Forums Salesforce® Discussions How to add Javascript Remoting to a Visualforce Page in Salesforce? Reply To: How to add Javascript Remoting to a Visualforce Page in Salesforce?

  • Parul

    Member
    September 18, 2018 at 1:36 pm

    Hi

    JavaScript code can be written in a Visualforce page and can be included in a Visualforce page by using a static resource within the script.

    Example: Code snippet

    <script type=”text/javascript”>
    function getRemoteAccount() {
    var accountName = document.getElementById(‘acctSearch’).value;
    Visualforce.remoting.Manager.invokeAction(
    ‘{!$RemoteAction.MyController.getAccount}’,
    accountName,
    function(result, event){
    if (event.status) {
    // Code for callback handling
    }
    }, {escape: true}
    );
    }
    </script>

     

    Controller:

    @RemoteAction
    global static String getItemId(String objectName) { … }

     

    Thanks