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
J DoveJ Dove 

Using Visualforce Pages in Mobile Cards – page isn't evaluating stage error when checking challenge

I'm getting an error when checking the Using Visualforce Pages in Page Layouts and Mobile Cards challenge. The error says that the page isn't evaluating the 'Prospecting' stage, yet the code works when I insert an Opportunity Id where the Stage = Prospecting.

The code:
<apex:page docType="html-5.0" standardController="Opportunity">
    <style>
    </style>
    
    <apex:remoteObjects >
        <apex:remoteObjectModel name="Opportunity" fields="Id,StageName" />
    </apex:remoteObjects>
    
    <div class="myPage">
        <h2>Tip for when you're in the {!Opportunity.StageName} Stage:</h2>
        <p id="stageTip" />
    </div>
    
    <script>
        var opportunityStage = "{!Opportunity.StageName}";
        document.getElementById("stageTip").innerHTML = createStageTip();
        
        function createStageTip() {
            if(opportunityStage){
                switch(opportunityStage){
                    case "Prospecting":
                        return "You need to ask really good questions"
                        break;
                    case "Needs Analysis":
                        return "Determine the needs by asking really good questions"
                        break;
                    case "Proposal/Price Quote":
                        return "Make sure the price doesn't exceed the budget"
                        break;
                    case "Negotiation/Review":
                        return "Maybe go down, but don't go down too much"
                        break;
                    default:
                        return "Use your best judgement";
                }
            }
        }
    </script>
</apex:page>
If you have any ideas as to why this isn't working, I'd love to hear them.

Cheers,
Justin
 
Best Answer chosen by J Dove
James LoghryJames Loghry
You're making the page a lot more complicated than it needs to be.  I don't think the challenge "checker" likes your javascript perhaps.  Here's an example of how I passed the challenge:
 
<apex:page standardController="Opportunity">
    <apex:outputText rendered="{!Opportunity.StageName=='Prospecting'}">Tips for prospecting</apex:outputText>
     ...repeat for all other stages..
</apex:page>


 

All Answers

James LoghryJames Loghry
You're making the page a lot more complicated than it needs to be.  I don't think the challenge "checker" likes your javascript perhaps.  Here's an example of how I passed the challenge:
 
<apex:page standardController="Opportunity">
    <apex:outputText rendered="{!Opportunity.StageName=='Prospecting'}">Tips for prospecting</apex:outputText>
     ...repeat for all other stages..
</apex:page>


 
This was selected as the best answer
J DoveJ Dove
I thought this might have been the case. It's a bummer, too, because I was really excited that my code above actually works (and I got it to work on first try!).
Andrew SturtAndrew Sturt

My code was even simpler and, like J Dove's, it works, but I too get the "page isn't evaluating the 'Prospecting' stage" announcement.

Here's my code:
 
<apex:page docType="html-5.0" standardController="Opportunity">

    {!CASE(Opportunity.StageName, "Prospecting","Tip for Prospecting", "Needs Analysis", "Tip for Needs Analysis", "Proposal/Price Quote", "Tip for Proposal/Price Quote", "Negotiation/Review", "Tip for Negotiation/Review", "Other")}

</apex:page>

Anyone know why this fails the challenge?
Eric KintzerEric Kintzer
this is probably a question for the moderator (Jeff D) as I used the same solution as Andrew and it failed with same error; the Trailhead VF page verification parser may not handle the CASE statement
Andrew SturtAndrew Sturt
I ended up doing nested IF statements, which should not be the preferred coding standard, but apparently the verification parser was okay with this code:
<apex:page docType="html-5.0" standardController="Opportunity">

    {!IF(Opportunity.StageName=="Prospecting","Tip for Prospecting",IF(Opportunity.StageName=="Needs Analysis", "Tip for Needs Analysis",IF(Opportunity.StageName=="Proposal/Price Quote", "Tip for Proposal/Price Quote",IF(Opportunity.StageName=="Negotiation/Review", "Tip for Negotiation/Review",""))))}

</apex:page>

 
Parker EdelmannParker Edelmann
I came up with the same code as you @Andrew Sturt (Using CASE), and got the same error. I hope you don't mind, but I copied your second code because I didn't want to type it. I've filed a feedback card, but does any one have a better way to get their attention? I'm a little new, so pardon me for asking, but who would have the power to correct the challenge?
Andrew SturtAndrew Sturt
Parker, I really don't know if there's any avenue to getting their attention other than the feedback card. Like you, I'm pretty new to this. My employer is moving to Salesforce, so I'm investing some time in learning how to work with the platform. Thanks for doing the feedback card.
Parker EdelmannParker Edelmann
No results yet from the feedback card. There exists a Chatter group called "Trailhead". Posted the complaint there. Here's the URL:  https://success.salesforce.com/_ui/core/chatter/groups/GroupProfilePage?g=0F9300000009NekCAE
Jay wang 1Jay wang 1
Same error here after 8 months? 
Ivan VrtacnikIvan Vrtacnik
Andrew, 

What's even worse is that your IF statement solution is actually incorrect. You used the double equals (==) Apex equality operator, when this is a formula and should therefore be using the formula equality operator (=).
Efraim Taranto 1Efraim Taranto 1
I passed the challenge using similar code than James L
 
<apex:page standardController="Opportunity">
    <apex:outputText rendered="{!Opportunity.StageName=='Prospecting'}">Tips for prospecting</apex:outputText>
    <apex:outputText rendered="{!Opportunity.StageName=='Needs Analysis'}">Tips for Needs Analysis</apex:outputText>
    <apex:outputText rendered="{!Opportunity.StageName=='Proposal/Price Quote'}">Proposal/Price Quote</apex:outputText>
    <apex:outputText rendered="{!Opportunity.StageName=='Negotiation/Review'}">Tips for Negotiation/Review</apex:outputText>
</apex:page>