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
Edwin HerreraEdwin Herrera 

Variables inside IF ELSE

Hi Everyone,
The 3 variables I am dealing with are  Final_Status_Summary__c, Status_Summary__c and Percent_Complete__c. I would like to display final status summary if percent complete is 100 otherwise display status summary on my page.
Best Answer chosen by Edwin Herrera
Edwin HerreraEdwin Herrera
This is how I was able to do it.

<apex:inputTextarea richText="true" cols="100" rows="16" value="{!Work_Item__c.Final_Status_Summary__c}"
rendered="{!IF(Work_Item__c.Percent_Complete__c==100, true, false)}"/>
<apex:inputTextarea richText="true" cols="100" rows="16" value="{!Work_Item__c.Status_Summary__c}" 
rendered="{!IF(Work_Item__c.Percent_Complete__c==100, false, true)}"/>
 

All Answers

VineetKumarVineetKumar
Assuming you are using the standard detail page to display the value.
You need to create a formulae field for showing the status : The formulae would be something like below
IF(Percent_Complete__c == 100, Final_Status_Summary__c, Status_Summary__c)

Let me know if this helps.
 
Edwin HerreraEdwin Herrera
I tried this line out and it does not populate any of the variables. It only populates the code itself on the page.
VineetKumarVineetKumar
Please share the formulae that you have written exactly
Edwin HerreraEdwin Herrera
<apex:inputField value="{!IF(Work_Item__c.Percent_Complete__c == 100,{!Work_Item__c.Final_Status_Summary__c}, {!Work_Item__c.Status_Summary__c})}"/>
With this code I am getting this error.
Error: Attribute value in <apex:inputField> must contain only a formula expression that resolves to a single controller variable or method


This is the following code line I have built up to. Earlier I had this.
{!IF(Work_Item__c.Percent_Complete__c == 100,"{!Work_Item__c.Final_Status_Summary__c}", "{!Work_Item__c.Status_Summary__c}")}
This code was outputting this on the page.         {!Work_Item__c.Status_Summary__c} 
 
VineetKumarVineetKumar
<apex:inputField value="{!IF(Work_Item__c.Percent_Complete__c == 100, Work_Item__c.Final_Status_Summary__c, Work_Item__c.Status_Summary__c)}"/>

 
Edwin HerreraEdwin Herrera
I have inputted the exact line you have provided and I am getting a Syntax error.
Error: Syntax error. Missing ')'.
There definitely is a close parentheses before the close bracket. Not sure what is causing it. I also made sure if the rest of the code is causing it, but it is not.
VineetKumarVineetKumar
The formulae is correct, try some other variations like
<apex:inputField value="{!IF(Work_Item__c.Percent_Complete__c == 100, 'TRUE', 'FALSE')}"/>

<apex:inputField value="{!IF(Work_Item__c.Percent_Complete__c != 100, 'TRUE', 'FALSE')}"/>


 
Edwin HerreraEdwin Herrera
Thank you very much for you assistance. Yes the formula definitely is right. I just dont know why I am getting that error. I will continue working on it. If you are able to figure anything else please let me know. Thank you
VineetKumarVineetKumar
just a curious thought, can you share me the controller code where you are setting the value for Percent_Complete__c.
Looks like Work_Item__c is an object, infact it should be an instance of object.
 
Edwin HerreraEdwin Herrera
I dont have a controller for this page. All the values for the fields were upserted to the object Work_Item__c. I have multiiple works Items and depending on the percent complete I want to display the final summart or just summary. Is there an issue with that?
VineetKumarVineetKumar
will it be possible for you to share the page code?
Edwin HerreraEdwin Herrera
<apex:page standardController="Work_Item__c" showHeader="false" standardStylesheets="false" >
<style>
body{background-color:white;}
h1
{
text-align:center;
}
</style>
<h1>Project Executice Summary</h1>
<apex:form >
<apex:pageBlock >
<apex:pageBlockSection columns="2" title="Work Item Details">

<apex:inputField value="{!Work_Item__c.Name}"/>
<apex:inputField value="{!Work_Item__c.Work_Item_ID__c}"/>
<apex:inputField value="{!Work_Item__c.Accountable_IT_Leader__c}"/>
<apex:inputField value="{!Work_Item__c.Work_Sponsor__c}"/>
<apex:inputField value="{!Work_Item__c.Forecasted_Finish__c}"/>
<apex:inputField value="{!Work_Item__c.Actual_Finished__c}"/>
<apex:inputField value="{!Work_Item__c.Percent_Complete__c}"/>
<apex:inputField value="{!Work_Item__c.LSEF_Stage_del__c}"/>
</apex:pageBlockSection>

<apex:pageblockSection title="Summary Indicators" columns="3">
<apex:inputField value="{!Work_Item__c.Status_as_of__c}"/>
<apex:inputField value="{!Work_Item__c.Overall_Health__c}"/>
<apex:inputField value="{!Work_Item__c.Quality_Scope_Health__c}"/>
<apex:inputField value="{!Work_Item__c.Schedule_Health__c}"/>
<apex:inputField value="{!Work_Item__c.Risk_Health__c}"/>
<apex:inputField value="{!Work_Item__c.Risks_Issues__c}"/>
<apex:inputField value="{!IF(Work_Item__c.Percent_Complete__c == 100, Work_Item__c.Final_Status_Summary__c, Work_Item__c.Status_Summary__c)}"/>
</apex:pageblockSection>

<apex:pageblockSection title="Project Costs">
<apex:inputField value="{!Work_Item__c.OpEx_Cost__c}"/>
<apex:inputField value="{!Work_Item__c.CapEx_Cost__c}"/>
</apex:pageblockSection>

<apex:pageBlockSection title="Report">
<apex:inputField value="{!Work_Item__c.Executive_Summary__c}"/>
<apex:inputField value="{!Work_Item__c.Value_Business_Outcomes__c}"/>
<apex:inputField value="{!Work_Item__c.Value_Measurement__c}"/>
</apex:pageBlockSection>

<apex:commandButton value="Save"/>
<apex:commandButton value="Delete"/>


</apex:pageBlock>
</apex:form>
</apex:page>
VineetKumarVineetKumar
Oh, that's so totally my mistake. How could I have missed that..!!
You cannot use IF condition in inputField tag
Since you said you just want to display the value on the page.
Please use the output tag
<apex:outputText "{!IF(Work_Item__c.Percent_Complete__c == 100, Work_Item__c.Final_Status_Summary__c, Work_Item__c.Status_Summary__c)}"/>

 
Edwin HerreraEdwin Herrera
I have inputted the code you have provide and I get the following error.
Error: WIP_STaRT line 31, column 18: Element type "apex:outputText" must be followed by either attribute specifications, ">" or "/>"
Error: Element type "apex:outputText" must be followed by either attribute specifications, ">" or "/>".
VineetKumarVineetKumar
There was a typo, the value attribute was missing.
<apex:outputText value="{!IF(Work_Item__c.Percent_Complete__c == 100, Work_Item__c.Final_Status_Summary__c, Work_Item__c.Status_Summary__c)}"/>

 
Edwin HerreraEdwin Herrera
This code is not giving me an error but it only shows final status summary or status summary but no content or box
VineetKumarVineetKumar
You might have to put some HTML styling/CSS around it.
<apex:outputPanel style="border: 1px solid black">
    <apex:outputText value="{!IF(Work_Item__c.Percent_Complete__c == 100, Work_Item__c.Final_Status_Summary__c, Work_Item__c.Status_Summary__c)}"/>
</apex:outputPanel>

Let me know if this helps.
Please help the community by selecting the best answer right under the comment, if my solution help you.
Should anyone facing similar issue may get the solution
Edwin HerreraEdwin Herrera
This is how I was able to do it.

<apex:inputTextarea richText="true" cols="100" rows="16" value="{!Work_Item__c.Final_Status_Summary__c}"
rendered="{!IF(Work_Item__c.Percent_Complete__c==100, true, false)}"/>
<apex:inputTextarea richText="true" cols="100" rows="16" value="{!Work_Item__c.Status_Summary__c}" 
rendered="{!IF(Work_Item__c.Percent_Complete__c==100, false, true)}"/>
 
This was selected as the best answer