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
Pawan Kumar 32Pawan Kumar 32 

Create a Visualforce page which shows a basic Contact record

Hello All,
I am stuck in below trailhead chanllange. Please help me.

Using the Contact standard controller, create a Visualforce page which displays a Contact's First Name, Last Name and the Email address of the Contact's Owner.The page must be named 'ContactView'.
It must reference the Contact standard controller.
It should include a bound variable that uses the standard controller to display the first name of the Contact.
It should include a bound variable that uses the standard controller to display the last name of the Contact.
It should include a bound variable that uses the standard controller to display the Contact Owner's email.

I am getting below error..
Challenge not yet complete... here's what's wrong:
The page does not include a bound first name variable for the Contact record
Please refer below screenshot for vf code.
User-added image
KaranrajKaranraj
Pawan - You don't have to use recordSetVar in your page which is to display collection of record, Trailhead challenge is to display information of single record. Just use standardcontroller alone in your visualforce pag that will clear the challenge.
Ajay K DubediAjay K Dubedi
Hi Pawan ,
Try this piece of code  
<apex:page standardController="Contact">
  <apex:pageBlock title="Account Summary">
        <apex:pageBlockSection >
            First Name: {! Contact.FirstName } <br/>
            Last Name: {! Contact.LastName } <br/>
            Owner's Email: {! Contact.Owner.Email } <br/>
        </apex:pageBlockSection>
    </apex:pageBlock>
</apex:page>
Thanks.
Andrew EversleyAndrew Eversley
Thanx to Ajay for helping me with my code, I had to add in the Owner's Email line I had just the Contact.Email as below

Contact Email: {! Contact.Email } <br/>
Should Be
Owner's Email: {! Contact.Owner.Email } <br/>
Jairo TenorioJairo Tenorio
I had a similar case with that detail "Owner's Email", it was funny!
Kunal KanaujiyaKunal Kanaujiya
Try this....it is also working :)

<apex:page sidebar="false" standardController="Contact">
    <apex:pageBlock title="Contact Summary">
        <apex:pageBlockSection>
            First Name: {! Contact.firstname} <br/>
            Last Name: {! Contact.lastname} <br/>
            Owner Email ID: {! Contact.Owner.email} 
        </apex:pageBlockSection>
    </apex:pageBlock>
    
</apex:page>
Muhammad AlaaMuhammad Alaa
Try This
<apex:page sidebar="false" standardController="Contact">
    <apex:pageBlock title="Contact View">
        <apex:pageBlockSection>
            First Name: {! Contact.FirstName} <br/>
            Last Name: {!Contact.LastName} <br/>
            Owner Email: {!Contact.Owner.Email} <br/>
        </apex:pageBlockSection>
    </apex:pageBlock>
</apex:page>

 
girikumar reddygirikumar reddy
ThankQ
Ajay
Sachin Ks 5Sachin Ks 5
Hi All,

Sorry for the Super late reply (Newbie to SF), You have probably figured it all out, anyways this is for reference to anybody having this issue.

The code i used to solve this unit is given below \,,/

Note: Typing this code will not show you the result on the Preview screen. If you want to see the output, you need to add the ID of any Contact Record in the Preview URL(Which can be tricky from badger). You need to login to your developer edition and try concatenating the Record ID if you are particular to see the output for yourself.

Do not worry about what you are not seeing on the preview screen, Save this code and Check Challenge, you are through to the next Unit :)
<apex:page standardController="Contact" Sidebar="False">
<apex:form >
    <apex:pageBlock >
        <apex:pageBlockSection >
           Contact First Name : {!Contact.FirstName}<br/>
           Contact Last Name : {!Contact.LastName} <br/>
           Email Address : {!Contact.Email} <br/>
           Contact Owner Email : {!Contact.Owner.Email}
                   
        </apex:pageBlockSection>
    </apex:pageBlock>    
</apex:form>
  
</apex:page>

Cheers,
Sachin Ks
Mayur TripathiMayur Tripathi
Hi Sachin,

Good Explanation, moreover coming to the second part of your answer which says  "you need to add the ID of any Contact Record in the Preview URL(Which can be tricky from badger)." Well in this case will navigate to the Contact-->click on any particular contact-->note the in this page (in the URL section) there would be an unique id, something like this https://ap5.lightning.force.com/one/one.app#/sObject/0037F000001oU2FQAU/view which is in my case (highlighted one), take this and paas it in your visualforce preview page along with "&id=0037F000001oU2FQAU", Hope it helps.

Cheers,
Mayur Tripathi
Pradeep SripadaPradeep Sripada
Thank you very much. It helped. 
Abhijeet DoiphodeAbhijeet Doiphode
Try this, it'll help to complete the challenge:
 
<apex:page standardController="Contact" Sidebar="False">
<apex:form >
    <apex:pageBlock >
        <apex:pageBlockSection >
           Assistant Name : {!Contact.AssistantName}<br/>
           Assistant Phone : <a href="tel:{!Contact.AssistantPhone}">{!Contact.AssistantPhone}</a> <br/>
           Email Address : {!Contact.Email} <br/>
           Assistant Owner Email : {!Contact.Owner.Email}
                   
        </apex:pageBlockSection>
    </apex:pageBlock>    
</apex:form>
  
</apex:page>

Best regards,
Abhi
EWilsonEWilson
Hi,

I'm trying to implement something similar to the original post and wondered about a few things:

1) How would you pull in a whole page section of fields from a contact record into a VF page using standard controller?
2) How would you pull in certain related lists on the contact record?
3) How can you ensure a logged-in user see only their own contact record data in these VF pages and no one elses?

If anyone has any links on this or has done similiar, any help would me massively appreciated. Thanks.
Swetaleena SalesforceSwetaleena Salesforce
Here Contat.Owner.Email means Email field from the User table, if i am correct.
Now my qs is in lightning if i see Fields and Relationship for User in Object manager, i cant see the Email field. But in Classic i can see in Build->Cutomize->Users->Fields

So if i want to know which field to refer in a look up relationship or the fields name and API names can i get it in lightning like i get it in classic?
 
Lavanya GaurLavanya Gaur
I am having a doubt. They have asked us that we have to display the contact's owner's email address. In fields and relationships for contact, the field name is mentioned as 'OwnerId' (type - Lookup(user)). But when we click on the Contact Owner, the field name is shown as 'Owner' with the help of which we can access the required data. So what is this 'OwnerId' then?

User-added image
User-added image
Sohail Arif 9Sohail Arif 9
@lavana, I have the same question as you.
Suryanarayan BeheraSuryanarayan Behera
This is below code you have to write;
<apex:page standardController="Contact" >
    <apex:pageBlock title="Contact Record">
    First Name: {! Contact.FirstName} <br/>
    Last Name: {! Contact.LastName}   <br/>
    Owner Email: {! Contact.Owner.Email} <br/>
    </apex:pageBlock>
</apex:page>
Harshit Jain 54Harshit Jain 54
Almost all of the above codes are okay, and if you couldn't see any output for it that's okay, actually that's expected. Just hit the Earn points button.
<apex:page standardController="Contact">
            {!Contact.FirstName}
            {!Contact.LastName}
            {!Contact.Owner.Email}
</apex:page>

That's enough.
Charlie DickCharlie Dick
Now I'm really confused.  When I look at the fields in the Contact object there is no firstname nor lastname fields yet this is what works in the challenge.  I assumed we had to create custom fields as the only one was name and then use them.   Or is this a function of the name type field that is a composite field?
Antonio RochaAntonio Rocha

Hi Charlie,

this is a function of the name type field that is a composite field, you don't need create a custom fields.

 

use this code.

<apex:page standardController="Contact" recordSetVar="Contacts">
    <apex:pageBlock title="ContactView">
        <apex:pageBlockSection >
            First Name: {!Contact.FirstName} <br/>
            Last Name: {!Contact.LastName} <br/>
            Owner Email:{!Contact.Owner.Email} <br/>
        </apex:pageBlockSection>
    </apex:pageBlock>
</apex:page>