0

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:

{!REQUIRESCRIPT('/soap/ajax/26.0/connection.js')} 
{!REQUIRESCRIPT('/js/functions.js')} 
{!REQUIRESCRIPT('/resource/jQueryForPopup/jQuery/jquery-1.8.2.min.js')} 
{!REQUIRESCRIPT('/resource/jQueryForPopup/jQuery/ui/jquery-ui-1.9.1.custom.min.js')} 
{!REQUIRESCRIPT('/resource/jQueryForPopup/jQuery/postmessage/jquery.ba-postmessage.js')} 
{!REQUIRESCRIPT('/resource/jQueryForPopup/jQuery/bbq/jquery.ba-bbq.min.js')} 
requireCssFile('/resource/jQueryForPopup/jQuery/ui/css/ui-lightness/jquery-ui-1.9.1.custom.min.css'); 

function requireCssFile(filename) 
{ 
var fileref = document.createElement('link');
fileref.setAttribute('rel', 'stylesheet');
fileref.setAttribute('type', 'text/css');
fileref.setAttribute('href', filename);
document.getElementsByTagName('head')[0].appendChild(fileref);
}

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" />') 
.dialog({ 
autoOpen: false, 
title: 'Add Details', 
resizable: true, 
width: 800, 
height: 540, 
autoResize: true, 
modal: true, 
draggable: true 
});

j$modalDialog.dialog('open');

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.

Thanks.

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:

/apex/Add_address?id=003i000000oeRVV

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 Jul 21 '14 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 Jul 21 '14 at 9:39
  • @keith..Thanks a lot. But when i try to print the value of this id parameter it gives me 'null'.. – juhi Jul 21 '14 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 Jul 21 '14 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 Jul 21 '14 at 14:25

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.