0

I have a custom button on Quote standard detail page which on Click opens up a Jquery dialogue box containing an iframe with src as a visualforce page(rendered as pdf) and contains two Button "save" and "Save and Email". a)Is it possible call a Apex class method when we click on these button, if yes how can we achieve this. b)If No, how can we achieve this with any other approach.

Here is the code for the javascript Custom button :-

    {!REQUIRESCRIPT('//ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js')} 
{!REQUIRESCRIPT('//ajax.googleapis.com/ajax/libs/jqueryui/1.11.2/jquery-ui.min.js')} 

var j$ = jQuery.noConflict();
var iframe_url = '/apex/CustomVisualforcePageRenderedAsPdf';

var j$modalDialog = j$('<div></div>') 
.html('<iframe id="iframeContentId" src="' + iframe_url + '" frameborder="0" scrolling="auto" height="100%" width="100%" marginheight="0" marginwidth="0" scrolling="no" />') 
.dialog({ 
    autoOpen: false, 
    title: 'Support Merge Fields', 
    resizable: false, 
    width: 700, 
    height: 300, 
    autoResize: true, 
    modal: true, 
    draggable: false,
buttons: [
        {
            text: "Save",
            click: j$.noop,
            type: "submit"
        },
        {
            text: "Save And Email",
            click: function() {
                j$( this ).dialog( "close" );
            }
        }
    ] 
}); 

j$modalDialog.dialog('open');
| improve this question | | | | |
  • Remote action function allow you to call apex class function from Javascript – NITHESH K Sep 15 '17 at 13:06
  • @NITHESHK, this script is not present on a visualforce page and is present on a custom javascript button. – Jitesh Goel Sep 15 '17 at 13:08
2

Yes, you can. See Apex in AJAX for details, but basically, you'll bind some functions to call more functions.

{!RequireScript('/soap/ajax/40.0/connection.js')}
{!RequireScript('/soap/ajax/40.0/apex.js')}

....

click: function() {
    var result = sforce.apex.execute('ClassName','Method',{ params ... })
},
| improve this answer | | | | |

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.