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

  • How can you call a controller method from JavaScript in salesforce?

    Posted by Laveena on September 30, 2019 at 1:43 pm

    How can you call a controller method from JavaScript in salesforce?

    Yogesh replied 3 years ago 2 Members · 1 Reply
  • 1 Reply
  • 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