+ Start a Discussion
BWSBWS 

Trailhead: Visualforce Basics: Using Simple Variables and Formulas: Challenge

The Challenge for this (https://developer.salesforce.com/en/trailhead/force_com_programmatic_beginner/visualforce_fundamentals/visualforce_variables_expressions)Trailhead unit asks us to create a VisualForce page named "myHelloWorldVF" that displays the first name of the logged-in user.

Here is the VF I am using:
<apex:page>
{!$User.FirstName}
</apex:page>
(note: I have also tried wrapping the binding inside tags like <div>, <p>, <apex:outputText>, etc with no luck. I also tried minimizing the rendered output by including sidebar="false" standardStylesheets="false" showHeader="false")

The error returned in Trailhead after clicking "Check Challenge" is:
"Challenge not yet complete... here's what's wrong: 
The Visualforce page did not fit the criteria. The first name of the loged in user was not output using dynamic global variables." 

I am not aware of a different global var within VF for getting User attributes.

Anyone have luck with getting this one to pass?
Best Answer chosen by BWS
Sandeep BhanotSandeep Bhanot
Hi,
Thank you for identifying this issue with the Visualforce challenge. We were able to replicate the issue and we found an error in our challenge implementation. We've pushed out a fix and so you can now attempt the challenge again and it should pass this time (you already have the right markup).
Apologies for the bug and thanks again for flagging the issue and helping us make Trailhead better! I would also love to get any suggestions/feedback that you might have on how we can improve the the overall Trailhead experience/content/chanllenges etc. (just use the 'Send Feedback' link in the app). Thanks
Sandeep 

All Answers

PratikPratik (Salesforce Developers) 
Hi,

To get Logged in user's first name: 
{!$User.FirstName}

Here is the list of different global variables in Salesforce:
https://www.salesforce.com/us/developer/docs/pages/Content/pages_variables_global.htm

Thanks,
Pratik

P.S. If this answers you question, please mark it as "Best Answer" so it will help other community members too.
JeffreyStevensJeffreyStevens
That's what he did - {!User.FirstName}.

I tried it also - and got the invalid message also.  Think it's possible that the Check has a bug in it?

Jeff
BWSBWS
Thank you @JeffreyStevens for reading the full question and testing the same scenario.

I am not exactly sure how the Trailhead app is checking and validating the VisualForce markup for this Challenge. 

One GUESS is that it is using the Tooling API (via the Oauth access we grant it when starting the Challenge) to pull the specific ApexPage and inspect the Markup attribute for the appropriate use of "$User.FirstName". However, I am not exactly sure if it can do that as a "Connected App". I have never specifically built something like that (at least not yet).

I tested this out via the Rest Explorer in Workbench:
“/services/data/v32.0/query?q=SELECT+Markup+FROM+ApexPage+WHERE+Name+=+'myHelloWorldVF'”

Here are the results:
> totalSize: 1
> done: true
> records
>> myHelloWorldVF
>>> attributes
>>>> type: ApexPage
>>>> url: /services/data/v32.0/sobjects/ApexPage/066j0000000Y1arAAC
>>> Id: 066j0000000Y1arAAC
>>> Name: myHelloWorldVF
>>> Markup: <apex:page > {!$User.FirstName} </apex:page>



Sandeep BhanotSandeep Bhanot
Hi,
Thank you for identifying this issue with the Visualforce challenge. We were able to replicate the issue and we found an error in our challenge implementation. We've pushed out a fix and so you can now attempt the challenge again and it should pass this time (you already have the right markup).
Apologies for the bug and thanks again for flagging the issue and helping us make Trailhead better! I would also love to get any suggestions/feedback that you might have on how we can improve the the overall Trailhead experience/content/chanllenges etc. (just use the 'Send Feedback' link in the app). Thanks
Sandeep 
This was selected as the best answer
BWSBWS
Thanks for looking into this Sandeep. The Check is now passing and working as expected. The current exercises were a great refresher and should be invaluable for anyone new to the platform or just looking to get back to basics. I will share additional feedback as suggested.
Ramanujam Varadhan 4Ramanujam Varadhan 4
I think the bug is still not fixed. I am getting the same error for the same code.
Sandeep BhanotSandeep Bhanot
Can you make sure that you don't have any whitespaces in your expression and please try again? i.e. don't use {! $User.FirstName }, but rather {!$User.FirstName}
Ramanujam Varadhan 4Ramanujam Varadhan 4
Hi Sandeep,
Thanks a lot.

The challenge was cleared after removing the white spaces.
Frédéric TrébuchetFrédéric Trébuchet
Hi,

Also got a problem with this challenge as my fristname contains accented caracters ("é" in my case).
If fact, I hve replaced these caracters by "e" and the challenge was OK.

Hope this helps, specially those with this kind of caracters in their first name, and also guys behind the scene that make things possible with this very cool learning tool.

Regards,
Fred


 
Salesforce AnswersSalesforce Answers
A video showing the solution to this challenge is located here. ======> https://www.youtube.com/watch?v=wFCH1L9ygSA

                        --- Salesforce Answers
lakshmi navyasri edpugantilakshmi navyasri edpuganti
Try This :
<apex:page>
{!$User.FirstName}
</apex:page>
Aditya PanditaAditya Pandita
Problem is still there
Sahu AnujSahu Anuj
Use {!$User.FirstName} {!$User.LastName} it works.
vaibhav patil 41vaibhav patil 41
Getting Following Error, 
"The first name of the currently logged-in user isn't output on your page using dynamic global variables."
With code 
<apex:page >
   <apex:pageBlock title="Display User Info">
    <apex:pageBlockSection columns="1">
        {! IF($User.IsActive,$User.FirstName & ' ' & $User.LastName, $User.FirstName & ' ' &$User.LastName & "is inactive")}
        <p>This user is currently {! IF($User.IsActive, 'Active', 'Inactive')}</p>
            <p>When logging in, they use the login of {! IF($User.IsActive, $User.Username, 'N/A')}</p>
       </apex:pageBlockSection>
    </apex:pageBlock>
</apex:page>

Can anyone help resolving this issue?
 
Preethi K 9Preethi K 9
Hi @vaibhav patil 41

Try this,

<apex:page>
    <apex:pageBlock title="User Status">
        <apex:pageBlockSection columns="1">
            {!$User.FirstName}+' '+{!$User.LastName}
            ({! IF($User.isActive, $User.Username, 'inactive') })
        </apex:pageBlockSection>
    </apex:pageBlock>
</apex:page>