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
gowthamckgowthamck 

Problem with IF statement statement

I am developing a Visual force page for endering a pdf file, with the VF page i want to put in IF Condition, but am facing couple of problem. i would like to check the oppty line item value to diplay the total price

 

My If statement is;

<apex:OutputField value="{!IF((!line.Bill__c="VC"),{!line.TotalPrice},null)}"/>

 

My table code is

<apex:repeat value="{!Opportunity.OpportunityLineItems}" var="line">
          <tr>
             <td>{!line.PricebookEntry.Name}</td>
             <td>{!line.PricebookEntry.Product2.Status__c}</td>             
             <td>{!line.Quantity}</td>
             <td><apex:OutputField value="{!line.UnitPrice}"/></td>
             <td><apex:OutputField value="{!IF((!line.Bill__c="VC"),{!line.TotalPrice},null)}"/></td>
             <td><apex:OutputField value="{!IF((!line.Bill__c="FC"),{!line.TotalPrice},null)}"/></td>

          </tr>
       </apex:repeat>

 

Please let me know how to fix this issue.

blombardisblombardis

Hi gowthamck,

 

In an if statement you don{t have to put the "!" before the field, in your case the correct code will be:

 

 

{!IF((line.Bill__c="VC"),{line.TotalPrice},null)}

Good luck,

Bruno

 

gowthamckgowthamck

Hi, thank you for responding, but I tried inserting the syntax you gave it showed me as syntax error

 

<td><apex:OutputField value="{!IF((line.Bill__c="VC"),{line.TotalPrice},null)}"/></td>

 

can you please see if this is rite??

blombardisblombardis

 

{!IF(line.Bill__c="VC",line.TotalPrice,null)}

 

 

Try with this, or 

 

 

{!IF(line.Bill__c='VC',line.TotalPrice,'')}

Let me know if this works,

Bruno

 

gowthamckgowthamck

Hi Bruno,

 

its giving me syntax error even after trying some corrections

 

<td><apex:OutputField value="{!IF((line.Bill__c=VC),{line.TotalPrice},null)}"/></td>

 

ThankX

CK

gowthamckgowthamck

 

<td><apex:OutputField value="{!IF(line.Bill__c='VC'),line.TotalPrice,'')}"/></td>

Syntax error. Extra ','

 

 

 <td><apex:OutputField value="{!IF(line.Bill__c='VC',line.TotalPrice,'')}"/></td>

 

 

 

Error: Syntax error. Missing ')'

 

blombardisblombardis

 <td><apex:OutputField value="{!IF(line.Bill__c=='VC',line.TotalPrice,'')} "/></td>

 

It's a comparation so it should be ==

 

Good luck :)

 

gowthamckgowthamck

<apex:OutputField value="{!IF(line.Bill__c=='VC',line.TotalPrice,'')}"/>

Am getting aerror : Missing ')'

blombardisblombardis

I don't know why the reason for this error, but if I put

 

 

<apex:OutputField value="{!IF(line.Bill__c=='VC',line.TotalPrice,'')}"/>

 

 

I see the same error, but with

 

 

<apex:OutputText value="{!IF(line.Bill__c=='VC',line.TotalPrice,'')}"/>

 

Its working.

Do you really need a OutputField?

 

gowthamckgowthamck

<apex:OutputText value="{!IF(line.Bill__c=='VC',line.TotalPrice,'')}"/>

 

error: Incorrect parameter for function IF(). Expected Number, received Text

 

as its a numaric Field , i think outputtext wont fit into this..

 


ahab1372ahab1372

if line.Bill__c is a numeric field, you cannot compare it to 'VC', only to a number

joss buttlerjoss buttler
In Visualforce, you have a few issues with your code. You should use the proper syntax for your IF conditions, and you don't need to use curly braces ({}) inside the IF statements. Here's the corrected code:
<apex:repeat value="{!Opportunity.OpportunityLineItems}" var="line">
    <tr>
        <td>{!line.PricebookEntry.Name}</td>
        <td>{!line.PricebookEntry.Product2.Status__c}</td>
        <td>{!line.Quantity}</td>
        <td><apex:OutputField value="{!line.UnitPrice}"/></td>
        <td>
            <apex:OutputText value="{!IF(line.Bill__c='VC', line.TotalPrice, null)}"/>
        </td>
        <td>
            <apex:OutputText value="{!IF(line.Bill__c='FC', line.TotalPrice, null)}"/>
        </td>
    </tr>
</apex:repeat>

Here are the key changes made to your code:
  1. In your IF statements, I removed the curly braces ({}) around the conditions. You should compare the values directly, like line.Bill__c='VC', without using {}. Look at this bill (https://lescobillonline.net/).
  2. I used the <apex:OutputText> component to conditionally display the TotalPrice based on the value of line.Bill__c. This is the correct way to conditionally display values in Visualforce.
With these changes, your Visualforce page should correctly display the TotalPrice based on the Bill__c value in your Opportunity Line Items.