You need to sign in to do that
Don't have an account?
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.
I think this is what you want:
All Answers
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.
Thanks for the update. But what I was really looking for was to get to the actual contact page.
I think this is what you want: