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
deplaideplai 

creating visualforce page to pull user info

I have a lookup field in contact to the user object.  For each user, I have a contact record as well.  I'm trying to create a VF page that will automatically pull the contact record of the current logged in user.

 

I'm still fairly new to VF, but so far I have created a class called "mycontact":

 

public class MyContact{
    
    private final Contact contact;
    
    public MyContact(){
        contact = [ select id from Contact where user__c = :UserInfo.getUserID()];
        }
        
    public Contact getContact() {
        return contact;
        }
 }

 

The question now is how do I write up the VF page to use this info and render the contact info automatically?  I will be using this VF page in a overridden tab.

 

I used something like this, but it requires me to click on it to show the info:

<apex:page Controller="MyContact" >
<apex:outputlink value="/apex/mycontact"> Click Here <apex:param name="id" value="{!contact.id}"/> </apex:outputlink>
<apex:detail />
</apex:page

 

Any help to a newbie would be greatly appreciated.  Thanks.

Best Answer chosen by Admin (Salesforce Developers) 
jwetzlerjwetzler

I think this is what you want:

<apex:page controller="MyContact" action="{!URLFOR($Action.contact.View, contact.Id)}">
</apex:page>

 

All Answers

Navatar_DbSupNavatar_DbSup

Hi,

 

Try the below code snippet as reference:

 

================ Apex controller ==================

public class cls_displaycontactinfo

{

 

  public final Contact contact;

  public user user1;

    public cls_displaycontactinfo (){

      

         user1= [ select contactid from user where id= :UserInfo.getUserID()];

         contact=[select name from contact where id=:user1.contactid];

        }

        public Contact getContact() {

        return contact;

        }

   

 }

 

============== Vf page ===================

 

<apex:page controller="cls_displaycontactinfo" >

  <apex:outputText value="{!contact.name}"> </apex:outputText>

 <apex:outputText value="{!contact.email}"> </apex:outputText>

</apex:page>

 

 

Did this answer your question? If not, let me know what didn't work, or if so, please mark it solved. 

deplaideplai

Thanks for the update.  But what I was really looking for was to get to the actual contact page.

jwetzlerjwetzler

I think this is what you want:

<apex:page controller="MyContact" action="{!URLFOR($Action.contact.View, contact.Id)}">
</apex:page>

 

This was selected as the best answer