I have a popup that shows up when a custom button is clicked on a standard Salesforce page. When the button is clicked a Javascript is executed that opens the popup. The Javascript code shows my VF page in the popup.

Here is the JAVASCRIPT that opens the popup and 'Add_address' is the name of my VF page:


function requireCssFile(filename) 
var fileref = document.createElement('link');
fileref.setAttribute('rel', 'stylesheet');
fileref.setAttribute('type', 'text/css');
fileref.setAttribute('href', filename);

var j$ = jQuery.noConflict();
var iframe_url = '{!URLFOR("/apex/Add_address")}';

var j$modalDialog = j$('<div id="opppopup"></div>')
.html('<iframe id="iframeContentId" src="' + iframe_url + '" frameborder="0" height="100%" width="100%" marginheight="0" marginwidth="0" scrolling="no" />') 
autoOpen: false, 
title: 'Add Details', 
resizable: true, 
width: 800, 
height: 540, 
autoResize: true, 
modal: true, 
draggable: true 


In my 'Add_address' VF page I have a field that needs to be prepopulated with a value that is to be fetched from the standard salesforce page that contains the custom button.

Please let me know how to go about it.



1 Answer 1


You don't say much about the logic of your Add_address Visualforce page, but I would have thought that you need to pass it the ID of the SObject that the standard Salesforce page is displaying.

So if the standard page is a Contact page, you could do that like this:

var iframe_url = '{! URLFOR('/apex/Add_address', null, ['id' = Contact.Id]) }';

so that the URL generated is of this form:


and your Add_address page controller can grab this value using:

Id id = (Id) ApexPages.currentPage().getParameters().get('id');

Once you have that SObject ID, the page's controller can query any value it needs itself rather than the button logic having to pass in the value. So no URL hacking is needed.

(It is possible to pull fields from the standard Salesforce page using JavaScript and pass them in the URL for the Add_address page, but you would need to hard code the field ID in the JavaScript and for fields like address deal with HTML markup. So unless you have a strong reason to implement that way, better to avoid it.)

Note that because the Visualforce page is served from a different subdomain than the standard Salesforce page, depending on what you are trying to do you may hit cross-origin problems.

  • The problem here is that there are no URLs seen on the popup. Is it still possible to fetch the values when the URL does not even appear on the popup?
    – juhi
    Commented Jul 21, 2014 at 9:37
  • @juhi The URL is being used via the src attribute of the iframe. The URL goes back to Salesforce (including any parameters) and Salesforce replies with HTML that is displayed in the iframe. So yes the above approach will work.
    – Keith C
    Commented Jul 21, 2014 at 9:39
  • @keith..Thanks a lot. But when i try to print the value of this id parameter it gives me 'null'..
    – juhi
    Commented Jul 21, 2014 at 12:33
  • @juhi What do you see if you add console.log(iframe_url); immediately after var iframe_url ..., turn on your browser's JavaScript console and click the button? This well help identify if the problem is in the button JavaScript or in your Add_address page controller.
    – Keith C
    Commented Jul 21, 2014 at 13:17
  • @keith..hey i just checked the URL is absolutely right. This is wat I got in console.log() as I hardcoded the Id as 36660 for now... "c.na17.visual.force.com/apex/Add_address?id=36660" But when I print this value with System.debug(id) in my controller it gives me NULL.
    – juhi
    Commented Jul 21, 2014 at 14:25

You must log in to answer this question.

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