Activity Forums Salesforce® Discussions How to execute Apex from Custom button or Javascript? Reply To: How to execute Apex from Custom button or Javascript?

  • Shubham

    Member
    March 22, 2016 at 1:23 pm

    In this case you can use apex action function.

      Example

    VF Page---
    <apex:page Controller="myController">
    <apex:form>
    <apex:actionFunction name="callAction" action="{!myFunction}" />
    <button type="button" onclick="callAction()">Call My Function</button>
    <apex:outputPanel rendered="{!panel}">
    Controller function Called.
    </apex:outputPanel>
    </apex:form>
    </apex:page>

    Apex Class---
    public class myController {
    public Boolean panel {get;set;}
    public myController(){
    panel = false;
    }
    public void myFunction(){
    panel = true;
    }
    }