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
Gleb VrevskyGleb Vrevsky 

Visualforce page - IF usage to compare string value for custom object

Hello!

Task: I am trying to create pretty much simple visualforce page. Table with 5 columns. Column 1 = Employee name. Column 2-5 = Employee completed courses.

Problem: Faced a problem creating columns for employee courses. These columns should output the TRUE or FALSE value e.g. if employee has completed a course or not. The current implementation looks like:
     
<apex:page standardController="CourseEnrollment__c" recordSetVar="records" id="thePage" cache="false"> 
<apex:form id="theForm"> 
    <apex:pageBlock id="thePageBlock"> 
        <apex:pageBlockTable value="{!records}" var="record" id="thePageBlockTable"> 
            <apex:column >
                <apex:outputField value="{!record.Employee__r.Name}" id="EmployeeNameDOM" /> 
                <apex:facet name="header">Name</apex:facet>
            </apex:column>
            <apex:column>
                <apex:outputText value="{!IF(!record.Course__r.Status == 'Completed','Completed','Expected')}" id="CourseNameDOM" /> 
                <apex:facet name="header">Course status</apex:facet>
            </apex:column>
        </apex:pageBlockTable> 
    </apex:pageBlock> 
</apex:form>
</apex:page>
The main object is CourseEnrollment, Employee and Course are related objects (master-details relation -> http://www.screencast.com/t/nLStStlAjzr)
Code above is just a test, trying to make IF statement work - no luck (also tried to use CONTAINS).

Question:
What is the right way to compare custom objects values on visualforce page? Is it worth to use custom controller, and get all required data already inside the custom class, not to complicate visualforce page structure?

 
Best Answer chosen by Gleb Vrevsky
Gaurav_SrivastavaGaurav_Srivastava
Hi Gleb Vrevsky,

try below statement-
<apex:outputText value="{!IF(record.Course__r.Status = 'Completed','Completed','Expected')}" id="CourseNameDOM" />

Thanks,
Gaurav

All Answers

Gaurav_SrivastavaGaurav_Srivastava
Hi Gleb Vrevsky,

try below statement-
<apex:outputText value="{!IF(record.Course__r.Status = 'Completed','Completed','Expected')}" id="CourseNameDOM" />

Thanks,
Gaurav
This was selected as the best answer
pconpcon
The problem is that you have a stray ! in front of your record.  What you want to do is
 
value="{!IF(record.Course__r.Status == 'Completed', 'Completed', 'Expected')}"

That should do what you want.