function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Nishad BashaNishad Basha 

How to display the contact detail page using visualforce page?

our requirement is when i click detail page button i want show the one contact details of that page. please give one example code for that scenario.please give some ideas.
Krishna SambarajuKrishna Sambaraju
Where is this Detail Page button going to be? Is it in another visualforce page?
Nishad BashaNishad Basha
when i click the Detail Page button  i need to display Detail Page records in the page
Nishad BashaNishad Basha

Amit Chaudhary 8

How to display the contact detail page using visualforce page?

when i click the Detail Page button  i need to display Detail Page records in the page.can you please give me the example of above scenario.
 
Krishna SambarajuKrishna Sambaraju
Sorry Nishad, you didn't understand my question. You said, when you click Detail Page Button, where did you add this button? Is it in a page layout or a different Visualforce page? Can you share a screenshot?
Nishad BashaNishad Basha

Hi, Krishna Sambaraju

visualforce page
Krishna SambarajuKrishna Sambaraju
Create a new visualforce page as below
Visualforce page (name: ContactDetailPage)
<apex:page standardController="Contact">
	<apex:detail/>
</apex:page>
Add the gotoContactDetailPage method to the controller or the extension class of the standardController of the current visualforce page.
public class ContactListController{
	public List<Contact> contacts {get; set;}
	public string contactId {get; set;}
	public ContactListController()
	{
		contacts = [select Id, FirstName, LastName from Contact LIMIT 10];
	}
	public PageReference gotoContactDetailPage()
	{
		return new PageReference('/apex/ContactDetailPage?id=' + contactId);
	}
}

Assuming your current visualforce page displays a list of contacts as shown in the below visualforce page
<apex:page controller="ContactListController">
	<apex:form>
		<apex:pageBlockTable>
			<apex:pageBlockTable value="{!contacts}" var="contact">
				<apex:column headValue="First Name" value="{!contact.FirstName}"/>
				<apex:column headValue="First Name" value="{!contact.FirstName}"/>
				<apex:commandButton value="Goto DetailPage" action="{!gotoContactDetailPage}" reRender="none">
					<apex:param name="contactid" value="{!contact.Id}" assignTo="{!contactId}"/>
				</apex:commandButton>
			</apex:pageBlockTable>
		</apex:pageBlockTable>
	</apex:form>
</apex:page>

In the above VF page you can see a comman button "Goto DetailPage", which has an apex:param. The id of the contact is assigned to a controller variable contactId.

Hope this helps.
 
Nishad BashaNishad Basha

Hi, Krishna Sambaraju
 above code is not getting result. can ypu please send me another code with example.
Krishna SambarajuKrishna Sambaraju
Hi Nishad,

Your requirement is not clear. Please share the VF page and the controller, and give your requirement clearly. For example, on clicking the button do you need to go to the standard page layout of contact or a custom visualforce page, or do you want to display the details in the same visualforce page etc

In the above example, on clicking the button it navigates to a custom visualforce page. If you want to it to navigate to standard page layout change the controller method as below.
 
public class ContactListController{
	public List<Contact> contacts {get; set;}
	public string contactId {get; set;}
	public ContactListController()
	{
		contacts = [select Id, FirstName, LastName from Contact LIMIT 10];
	}
	public PageReference gotoContactDetailPage()
	{
		return new PageReference('/' + contactId);
	}
}

Regards,
Krishna.

 
Nishad BashaNishad Basha
Hi, Krishna Sambaraju
details in the same visualforce page
Krishna SambarajuKrishna Sambaraju
Here is an update to all the code I have posted to meet your requirement of displaying the details in the same visualforce page.
ContactDetailPage:
<apex:page standardController="Contact" sidebar="false" showHeader="false">
	<apex:detail/>
</apex:page>
ContactListController:
public class ContactListController{
	public List<Contact> contacts {get; set;}
	public string contactId {get; set;}
	public String pageRef { get; set; } 
        public boolean showDetails {get; set;}
	public ContactListController()
	{
		contacts = [select Id, FirstName, LastName from Contact LIMIT 10];
		showDetails = false;
	}
	public PageReference gotoContactDetailPage()
	{	
		showDetails = true;
                pageRef = '/apex/ContactDetailPage?id=' + contactId;
                return null;javascript:void(0)
	}
}

ContactListPage:
<apex:page controller="ContactListController">
	<apex:form>
		<apex:pageBlock id="pageBlock1">
			<apex:pageBlockTable value="{!contacts}" var="contact">
				<apex:column headValue="First Name" value="{!contact.FirstName}"/>
				<apex:column headValue="First Name" value="{!contact.FirstName}"/>
				<apex:commandButton value="Goto DetailPage" action="{!gotoContactDetailPage}" reRender="pageBlock1">
					<apex:param name="contactid" value="{!contact.Id}" assignTo="{!contactId}"/>
				</apex:commandButton>
			</apex:pageBlockTable>
			<apex:pageBlockSection title="Contact Details" columns="2" rendered="{!showDetails}" >
				<apex:iframe src="{!pageRef}" scrolling="true" width="1000px;">
				</apex:iframe>
			</apex:pageBlockSection>
		</apex:pageBlock>
	</apex:form>
</apex:page>

Hope this helps.
Krishna SambarajuKrishna Sambaraju
Remove the javascript:void(0) on line 15 of the controller above.
Nishad BashaNishad Basha
Hi, Krishna Sambaraju
above  code not working properly .please give me another example about above scenario.
Nishad BashaNishad Basha
Hi, Amit Chaudhary 8


How to display the contact detail page using visualforce page?

when i click the Detail Page button  i need to display Detail Page records in the page.can you please give me the example of above scenario.
 
Krishna SambarajuKrishna Sambaraju
Hi Nishad,

Can you specify what is not working properly? I have given a working example. I have tested the functionality before sharing the code here. Please share your visualforce page and the controller, then I will have an idea about your requirement. You wanted to display the contact details on the same page, do you mean only the contact details, or you also want the related lists to be displayed. If you can provide a screenshot of what you are looking for, I will be able to help.

Regards,
Krishna.
sudharani530sudharani530
vf page1 : 
<apex:page controller="ext_contactDetails">
    <apex:form>
        <apex:pageBlock>
            <apex:pageBlockSection title="Contacts ">
                <apex:pageBlock title="Contacts Lists">
                    <apex:pageBlockTable value="{!con}" var="cc">
                        <apex:column headerValue="Name">
                            <apex:commandLink value="{!cc.Name}" action="{!gotoContactDetailPage}">
                                <apex:param name="ccId" value="{!cc.Id}" assignTo="{!contactId}"/>
                            </apex:commandLink>
                        </apex:column>
                        <apex:column value="{!cc.FirstName}"/>
                        <apex:column value="{!cc.LastName}"/>
                        <apex:column value="{!cc.Phone}"/>                        
                    </apex:pageBlockTable>                    
                </apex:pageBlock>
            </apex:pageBlockSection>
        </apex:pageBlock>
    </apex:form>
</apex:page>

--------------------
vf page 2:  

<apex:page standardController="Contact">
    <apex:detail relatedList="false" />
</apex:page>

----------------------

Controller:


public class ext_contactDetails {
    
    public List<Contact> con {get;set;}
    public string contactId {get;set;}
    
    public ext_contactDetails(){
        con = [SELECT Id, Name, FirstName, LastName, Phone FROM Contact Limit 10];
    }
    
    public PageReference gotoContactDetailPage()
    {
        return new PageReference('/apex/vf5?id=' + contactId);
    }
}​
dpardpar
<apex:page standardController="Contact" recordSetVar="contacts" tabstyle="contact" sidebar="false">
<apex:pageBlock title="Contacts View for Ambassadors">
 <apex:form >
 <apex:pageBlockTable value="{!contacts}" var="a" id="list">
<apex:column value="{!a.name}"/>
<apex:column value="{!a.gender__c}"/>
 </apex:pageBlockTable>
 </apex:form>
 </apex:pageBlock>
</apex:page>
Suraj Tripathi 47Suraj Tripathi 47
Hi Nishad Basha,
For your reference, I have added a code example below.
<apex:page standardController="Contact" recordSetVar="contacts" >
<apex:form >
<apex:pageBlock title="Contact_list" id="Contact_list">
<apex:pageBlockTable value="{!contacts}" var="con">
<apex:column value="{!con.FirstName}"/>
<apex:column value="{!con.LastName}"/>
<apex:column>
<apex:commandButton action="/{!con.Id}" value="view"/>
</apex:column>
</apex:pageBlockTable>
<tr>
<td align="center">
<apex:commandLink action="{!Previous}" value="<< Previous" rendered="{!HasPrevious}"/>
<apex:outputText style="color: #ccc;" value="« Previous" rendered="{! NOT(HasPrevious) }"/>

<apex:commandLink action="{!Next}" value=" Next >>" rendered="{!HasNext}"/>
<apex:outputText style="color: #ccc;" value="Next >>" rendered="{! NOT(HasNext) }"/>
</td>
<td align="right">
<apex:selectList value="{!PageSize}" size="1">
<apex:selectOption itemValue="5" itemLabel="5"/>
<apex:selectOption itemValue="15" itemLabel="15"/>
<apex:actionSupport event="onchange" rerender="Contact_list"/>
</apex:selectList>
</td>
</tr>
</apex:pageBlock>
</apex:form>
</apex:page>
Please Mark this as the best answer if you find your solution. 

Thanks and Regards,
Suraj Tripathi