I have used following the code in my Onclickjavascript(custom button).

I have used two buttons in his pop and I would like to call the apex method from here.So, kindly let me know how to achieve this?


    var j$ = jQuery.noConflict();
    var iframe_url =  '{!URLFOR("/apex/apexpage")};
    var j$modalDialog = j$('<div id="opppopup"></div>')
    .html('<div align="center" style="margin-bottom:5px;"><input type="button" value="Save" class="btn" style="width:50px;"/>

<input type="button" value="Update" class="btn" /></div>

    <iframe  />') 

    autoOpen: false, 
    title: 'PDF Preview', 
    resizable: true, 
    width: 800, 
    height: 540, 
    autoResize: true, 
    modal: true, 
    draggable: true 

Apex method:

Public Class TestMethod(){        
    Public void Update(){


How to call the "Update" method when click the button in the above javascript frame code?

  • @highfive do you know the answer? Jul 18, 2014 at 6:43
  • Can't you have <apex:commandButton /> for this instead an HTML button? Is so you can simply set action="{!update}" to call the method. Also is this your controller of your VF page?
    – highfive
    Jul 18, 2014 at 6:47
  • Yes, but I would like to call from that html button. Jul 18, 2014 at 7:01

3 Answers 3


You can achieve by using the java script remoting.



There are several ways to do this.

  1. Using JavaScript Remoting
  2. Using <apex:actionFunction />

If you go with <apex:actionFunction /> add following line in your VF page

<apex:actionFunction action="{!update}" name="callJS" />
<input type="button" value="Update" onclick="callJS();" class="btn" />

This will trigger your Update() function in the controller.

Based on your requirement you can decide what option to be selected. Basically if you need to manage post back and rerender some areas upon the postback, you have to go with <apex:actionFunction /> while remote call methods call back functions handle it asynchronously.

  • the button is in the ifram(javascript) so How can I call the apex method. Jul 18, 2014 at 7:09

If want to call apex from Javascript then you'll need to make your class global and your method a webservice.


global with sharing class myClass {

  webService static void myMethod(id anId){ // do something}

Then call your apex via:-


var retStr; 
retStr = sforce.apex.execute("myClass", "myMethod", {anId:'{!mySObject.Id}'}); 

More info here (https://www.salesforce.com/us/developer/docs/apexcode/Content/apex_and_ajax.htm)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.