I have requirement in which on a certain condition i have to show an alert box in which i will have a link and a button. On click of the link i have to do some logic and do some DML operations. What i want to do is that i want to show a custom visualforce page having the link and button and show that page in a iframe in the alert box. Is this possible or i have to look other way around. Also is there anyway i can i can do this by jquery.

2 Answers 2


Here is what you can do Create a custom button and fill in the details and in "Behavior Section" choose "Execute JavaScript" and for "Content Source" choose "OnClick JavaScript",and in the code section paste the following code

    function showSimpleDialog(){
   var sd = new SimpleDialog("Test"+Dialogs.getNextId(), true);
sd.setTitle("Simple Dialog");
window.parent.sd = sd; sd.setWidth("50%"); //Specify the iFrame and give URL of VF page sd.setContentInnerHTML("");

if ($(sd.dialog).find('#InlineEditDialogX').size() == 0) { var close = $("<a id='InlineEditDialogX' title='Close' tabindex='0' href='javascript:void(0)' class='dialogClose'>Close</a>"); close.mouseover(function() { this.className = 'dialogCloseOn'; }).mouseout(function() { this.className = 'dialogClose'; }).click(function() { // finally our on click handler which closes the dialog sd.hide(); }); // insert the new generated close button before the h2 tag so it'll show up on the top right corner close.insertBefore($(sd.dialog).find('.topLeft h2')); } sd.show(); } showSimpleDialog();

This will bring up a modal where you can display your visual force page through iFrame and further through controller you can do all the DML operations.

  • Thanks Pawan. This is exactly something that i wanted. But in the sd.setContentInnerHTML(""); when i am putting my iframe in the this, in the src attribute of it i can't enter my complete url coz it's having paprameter's as well. Can you please tell me how could i make this url work.?? i.e. my url is something lyk this /apex/testpage?id='a1234567890789'&name='test' Can you please help me on this..
    – NaveenRaw
    Jan 29, 2014 at 15:43
  • done it(just have to add the +url+ in the url). Thanks. The solution works as per my requirement.
    – NaveenRaw
    Jan 29, 2014 at 15:51
  • How can i close the dialog box from my iframe's VF page. And re-render my parent VF page to new href from the child VF page(i.e. in the iFrame).
    – NaveenRaw
    Jan 30, 2014 at 13:27
  • 1
    You cant close it with iframe's VF page What you can do is after "sd.hide" type "window.location.reload(true)" this will refresh the parent page
    – Pavan
    Feb 12, 2014 at 15:08

You can't use JavaScript's alert function, but you could create a popup div element that contains the logic you would like to use. One sound method for this would be something like a Lightbox, where the content would be hosted in a fixed position, z-indexed div that hovers over the rest of the page content. There are numerous examples for this online. I've personally used this on several occasions with success, although I don't have a convenient example I can copy and paste. The iframe isn't strictly necessary, since you could just graft the DOM elements directly into the Visualforce page's DOM, but that is purely a matter of preference.

  • Pretty neat solution for sure. Thanks. One thing also i want to add that isn't it possible by some other means i could do this functionality.(without adding the lightbox js and images in my static folder) a built in thing for salesforce or in javascript.
    – NaveenRaw
    Jan 29, 2014 at 14:12
  • @NaveenRaw Not sure if this is a clarification question, but in short, yes, there is no publicly available, Salesforce-native means of accomplishing your goal. Salesforce uses lightboxes for inline editing, etc, but these aren't publicly documented and can't be relied on. You do not need to use a static resource and/or a library; I've written a lightbox in just a couple dozen lines of code, it's not hard.
    – sfdcfox
    Jan 29, 2014 at 14:21
  • Okay. will try that. one day will catch up with you on making such fine coding of writing lightbox in only dozen of lines !.. thanks.
    – NaveenRaw
    Jan 29, 2014 at 15:56

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .