Reader small image

You're reading from  Visualforce Development Cookbook

Product typeBook
Published inSep 2013
Reading LevelIntermediate
PublisherPackt
ISBN-139781782170808
Edition1st Edition
Languages
Right arrow
Author (1)
Keir Bowden
Keir Bowden
author image
Keir Bowden

Keir Bowden is a 30-year veteran of the IT industry from the United Kingdom. After spending the early part of his career in the defence industry, he moved into investment banking systems, implementing systems for Banque Nationale de Paris, CitiGroup, and Deutsche Bank. In the late 1990s, Keir moved into Internet technologies, leading to a development of the order management and payment handling systems of one of the first European Internet shopping sites. Keir started working with Force.com in late 2008 and has been recognized multiple times by Salesforce as an MVP for his contribution and leadership in the community. In 2012, he became the first certified technical architect outside of Salesforce in EMEA, and he has served as a judge on several EMEA Technical Architect Certification Review Boards. Keir is also a prominent blogger on Apex, Visualforce and Lightning Components solutions; and a regular speaker at events such as Dreamforce, Cloud World Forum, and Salesforce World Tour. Keir is a chief technical officer of BrightGena—a Salesforce.com Platinum Cloud Alliance Partner in the United Kingdom, where he is responsible for the present and future technical strategies. Keir acted as a technical reviewer for the CRM Admin Cookbook before accepting the challenge of authoring this book, which also happens to be his first.
Read more about Keir Bowden

Right arrow

Opening a pop-up window


Pop-up browser windows have received mixed reviews in recent years. Originally created before tabbed browsers existed to display additional information without interfering with the page the user had navigated to, they were quickly hijacked and used to display advertisements and spam. Pop ups should be used sparingly in applications and wherever possible in response to an action by the user.

The target attribute can be specified as _blank on HTML hyperlink tags to open the link in a new window, but all modern browsers allow the user to specify that new windows should be opened as new tabs instead. Also, if the browser does open the URL in a new window, it will be of the same size as the existing window and block most of it. Opening a window in JavaScript allows for fine-grained control over many aspects of the pop-up window, for example, the size, and whether to display a toolbar.

In this recipe we will create a page that renders a list of accounts, displaying a very small subset of fields per row. A link will be provided on each row to allow the user to view full details of the account in a pop-up window.

Note

Note that there is no way to ensure that a browser will display a pop-up window. Pop-up blockers generally allow windows to be opened in response to an action by the user, such as clicking on a link, but it is possible for users to configure their browser to block all pop ups regardless of how they were triggered.

How to do it…

This recipe requires two Visualforce pages to be created: the main page containing the list of accounts and the pop-up window page. The pop-up page is referenced by the main page, so this will be created first.

  1. Navigate to the Visualforce setup page by clicking on Your Name | Setup | Develop | Pages.

  2. Click on the New button.

  3. Enter Popup in the Label field.

  4. Accept the default Popup that is automatically generated for the Name field.

  5. Paste the contents of the Popup.page file from the code download into the Visualforce Markup area.

  6. Click on the Save button to save the page.

  7. Navigate to the Visualforce setup page by clicking on Your Name | Setup | Develop | Pages.

  8. Locate the entry for the Setup page and click on the Security link.

  9. On the resulting page, select which profiles should have access and click on the Save button.

  10. Next, create the main account list page by navigating to the Visualforce setup page by clicking on Your Name | Setup | Develop | Pages.

  11. Click on the New button.

  12. Enter PopupMain in the Label field.

  13. Accept the default PopupMain that is automatically generated for the Name field.

  14. Paste the contents of the PopupMain.page file from the code download into the Visualforce Markup area.

  15. Click on the Save button to save the page.

  16. Navigate to the Visualforce setup page by clicking on Your Name | Setup | Develop | Pages.

  17. Locate the entry for the PopupMain page and click on the Security link.

  18. On the resulting page, select which profiles should have access and click on the Save button.

How it works…

Opening the following URL in your browser displays a list of accounts: https://<instance>/apex/PopupMain.

Here, <instance> is the Salesforce instance specific to your organization, for example, na6.salesforce.com.

Note

Note that as this page uses a standard list controller, the list of accounts displayed will be that of the last list view that the user accessed.

The detail link markup is as follows:

<apex:outputLink title="View detail in a popup window" 
    onclick="return openPopup('{!acc.Id}');">
    Details
</apex:outputLink>

The onclick attribute defines the JavaScript function to be invoked when the link is clicked; note the {!acc.id} merge field, which passes the ID of the chosen account to the function.

The JavaScript function uses the window.open function to open the new window.

var newWin=window.open('{!$Page.Popup}?id=' + id, 'Popup',          'height=600,width=650,left=100,top=100,resizable=no,scrollbars=yes,toolbar=no,status=no');

The final parameter details the features required for the new window as a comma separated list of name=value pairs.

Clicking on the Details link displays the full account details in a pop-up window.

See also

  • The Adding a custom lookup to a form recipe in Chapter 3, Capturing Data Using Forms shows how information can be captured in a pop-up window and passed back to the main window to populate input fields.

Previous PageNext Page
You have been reading a chapter from
Visualforce Development Cookbook
Published in: Sep 2013Publisher: PacktISBN-13: 9781782170808
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
undefined
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $15.99/month. Cancel anytime

Author (1)

author image
Keir Bowden

Keir Bowden is a 30-year veteran of the IT industry from the United Kingdom. After spending the early part of his career in the defence industry, he moved into investment banking systems, implementing systems for Banque Nationale de Paris, CitiGroup, and Deutsche Bank. In the late 1990s, Keir moved into Internet technologies, leading to a development of the order management and payment handling systems of one of the first European Internet shopping sites. Keir started working with Force.com in late 2008 and has been recognized multiple times by Salesforce as an MVP for his contribution and leadership in the community. In 2012, he became the first certified technical architect outside of Salesforce in EMEA, and he has served as a judge on several EMEA Technical Architect Certification Review Boards. Keir is also a prominent blogger on Apex, Visualforce and Lightning Components solutions; and a regular speaker at events such as Dreamforce, Cloud World Forum, and Salesforce World Tour. Keir is a chief technical officer of BrightGena—a Salesforce.com Platinum Cloud Alliance Partner in the United Kingdom, where he is responsible for the present and future technical strategies. Keir acted as a technical reviewer for the CRM Admin Cookbook before accepting the challenge of authoring this book, which also happens to be his first.
Read more about Keir Bowden