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
MandadiMandadi 

How to display Detail Page of an object from vf page.

 Hi All,

 

      I have button in vf page, whenever i click that button i want to display the detail page of that record.

 

      Can any one help me how to solve.

 

Thanks

 

Best Answer chosen by Mandadi
anchoviesanchovies

Hi Mandadi, 
You can use the following method as the button action:

public PageReference redirectToDetail()
{
PageReference redirect = new PageReference('/' + objectId); 
return redirect;
}

 where objectId is the SF Id of an object.

http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_system_pagereference.htm

All Answers

hitesh90hitesh90

Hi,

 

Below is the example to display Detail Page of an object from vf page.

 

FirstPage:

<apex:page standardController="Account">
    <script>
        function gotoDetailpage(){
            window.location.href = "/apex/SecondPage?id={!Account.id}";
            return false;
        }
    </script>
    <apex:form>
        <apex:commandButton value="Go to Detail page" onclick="return gotoDetailpage();"/>
    </apex:form>
</apex:page>

 

Secondpage:

<apex:page standardController="Account">
    <apex:detail/>
</apex:page>

 

 

Important :
Hit Kudos if this provides you with useful information and if this is what you where looking for then please mark it as a solution for other benefits.

Thank You,
Hitesh Patel
SFDC Certified Developer & Administrator & Advanced Administrator & Sales cloud consultant
My Blog:- http://mrjavascript.blogspot.in/

MandadiMandadi

Hi hitesh,

 

     How to display detail page of record using apex code,when button clicked...

anchoviesanchovies

Hi Mandadi, 
You can use the following method as the button action:

public PageReference redirectToDetail()
{
PageReference redirect = new PageReference('/' + objectId); 
return redirect;
}

 where objectId is the SF Id of an object.

http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_system_pagereference.htm
This was selected as the best answer