Salesforce Stack Exchange is a question and answer site for Salesforce administrators, implementation experts, developers and anybody in-between. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

This question already has an answer here:

I would like to create a popup window as an action button in my Opportunity layout that will show details from my Opportunity and its related Contacts and Clients. I imagine this must be done via Visualforce. Could someone help me do this or point me in the redirection on how I can achieve this?

I'd imagine this would invole a Visualforce page and an apex class.

share|improve this question

marked as duplicate by Vamsi Krishna, Samuel De Rycke, Eric, crmprogdev, Sergey Utko Aug 21 '14 at 14:13

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

Yes it would involve that but typically questions here are for something specific. You can use a Javascript button on the default layout to popup the VF page. a VF page and apex class can do the rest. – dphil Aug 21 '14 at 14:14
up vote 2 down vote accepted

You need to create one visualforce page that uses an Opportunity as standard controller:

<apex:page standardController="Opportunity" showHeader="false" sidebar="false">

        <apex:pageBlockSection title="Opportunity" columns="1">
            <apex:outputField value="{!Opportunity.Name}"/>
            <apex:outputText value="Contacts"/>
            <apex:pageBlockTable title="Contacts" 
                                 value="{!Opportunity.Contacts__r}" var="contact">
                <apex:column value="{!contact.Name}"/>
                <apex:column value="{!contact.Phone}"/>


Because the page uses a the standard controller i dont need to create any apex controller, salesforce will do it for me. You can access assotiated object (Opportunity) and all related objects (in this example Contacts).

Then you will need to create a new custom button for the Opportunity object that will open this page in a popup. Then add this button to the Opportunity layout (here you can learn how to create cutom buttons and add them to the layout). Use following javascript code in your custom button:

popup ="apex/OppPopup?id={!Opportunity.Id}", "newPopup", "width=620,height=390, scrollbars=no, location=no"); 

Where OppPopup is the name of my visualforce page.

The button will then look like this:

enter image description here

By clicking on the button a new popup window appears (OppPopup page):

enter image description here

share|improve this answer
Thank you for the great answer. One thing I noticed was that a parameter was passed in the URL, but its not mentioned of in the VisualForce page (or that I can see). Can I pass multiple parameters here? Would it be possible to also pass this data on screen to other functions? e.g. another page or apex class? – Imran Aug 22 '14 at 12:43
@Imran This is a point of the standard controller. You need to pass only one record id, then you can access all fields and all child relationships on the visualforce page. You can for sure create an apex extension for the standard controller if you need more functionallity then a standard controller can give. – Sergey Utko Aug 22 '14 at 12:54

I would recommend to start with this chapter in the manual:

It comes with some examples and is not too hard to understand. But you have to get familiar with the basic concepts of Visualforce and Apex.

If you want to combine the data as you asked, it depends very much on what you want to achieve in particular. Have a look at:

share|improve this answer

Not the answer you're looking for? Browse other questions tagged or ask your own question.