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
Abhishek Mishra 243Abhishek Mishra 243 

how to call record ID dynamically to show the details of contact object?

Hello Guys,

I have to show the details from the contact object to the visualforce page with the help of record ID but unfortunately it is not showing me anything on the visual force page, kindly check the code and help me out.

VF Code:
<apex:page showHeader="false" standardcontroller ="Contact" extensions="MyContactController">
    <apex:form >
        <apex:pageBlock title="Tenant Details"> 
            <apex:pageBlockSection columns="2">
                <apex:outputField value="{! Contact.FirstName}" label="First Name"/>
                <apex:outputField value="{! Contact.LastName}" label="Last Name"/>
             </apex:pageBlockSection>
            <br/>
            <br/>
            
            <apex:pageBlockSection columns="3">
                    <apex:outputField label="Status" value="{! Contact.Approval_Status__c}"/>
                    
                    <apex:outputField label="Effective Date" value="{! Contact.RegistrationDate__c}"/>
                    
                    <apex:outputField label="Expiry Date" value="{! Contact.ExpiryDate__c}"/>
            </apex:pageBlockSection>
            
            <apex:outputText value=""/>
            <div align="center" >
                <apex:commandButton value="Renew" />
            </div>
            
            
            
        </apex:pageBlock>
    </apex:form>
    
</apex:page> 

Apex Class:
public class MyContactController{
public String currentRecordId {get;set;}
public list<Contact> lstcon = new list<Contact>();
 
    public MyContactController(ApexPages.StandardController controller) 
    {
        currentRecordId  = ApexPages.CurrentPage().getparameters().get('id');
        lstcon = [SELECT Id, FirstName, LastName, Approval_Status__c, RegistrationDate__c, ExpiryDate__c FROM Contact where id =: currentRecordId ];
        
    }
  
}
Maharajan CMaharajan C
Hi Abhisek,

You can use any one of the below ways:

1. You have to add this vf page in page layout. Then it will automatically will fetch the contact details.

2.  Replace your salesforce base url in below and give this vf page then pass the record id.
https://maharajlwc-dev-ed--c.visualforce.com/apex/YourVFPageName?id=0030o00003XF0MO 

3. If you are calling from VF page:
 PageReference p = new PageReference('/apex/your_page_name?id=' + con.id);
 p.setRedirect(true);
 return p;   

Thanks,
Maharajan.C
Abhishek Mishra 243Abhishek Mishra 243
Hi Maharajan,
Thank you foryour valueable time.

I have to show this landing page for the community site, and I'm new to development.

So, can you please help me out for changing the base url to whichi desired.

Thanks in advance.