Activity Forums Salesforce® Discussions How can you call a controller method from JavaScript in salesforce?

  • Yogesh

    Member
    September 30, 2019 at 2:51 pm

    Hello,

    using the tag apex:actionFunction(A component that provides support for invoking controller action methods directly from JavaScript code using an AJAX request. An component must be a child of an component.)

    for an exaple :-

    Controller:-

    public class controller{
    public pageReference noiseSearch(){
    //logic
    return null;
    }
    }

    vf page:-
    So your button will be

    <apex:commandButton value="Search" onclick="check();" reRender="nPbt" />

    And your script function

    function check(){
    var user = document.getElementById('pg:frm:nPB:ip').value;
    if(user == ''){
    alert('Please Enter noise Name before Proceeding.');
    return true;
    }
    else
    noiseSearchAF();
    return true;
    }

Log In to reply.

Popular Salesforce Blogs

Popular Salesforce Videos