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
Tye HarrisonTye Harrison 

Can't use IF in VALUE attribute on VF email template

I am getting a "Syntax Error. Missing ')' " with the code below and have not got a clue why.
The issue has something to do with the IF statement inside the value attribute (around line 30) but if I replace the condition with something really simple like 0<1 I get no syntax error.
I left in a couple of commented out lines as an example of what I'm ultimately trying to accomplish.
Just let me know any other questions you have or details you need.
Thank you.

<messaging:emailTemplate subject="Statement" recipientType="Contact" relatedToType="c2g__codaMassEmailAccount__c">
    <messaging:htmlEmailBody >
        <p align="center">
            <img src="{!relatedTo.c2g__OwnerCompany__r.c2g__LogoURL__c}"/><br/>
            <small><apex:outputField value="{!relatedTo.c2g__OwnerCompany__r.c2g__Street__c}"/><br/>
            <apex:outputField value="{!relatedTo.c2g__OwnerCompany__r.c2g__City__c}"/><apex:outputText value=", "/><apex:outputField value="{!relatedTo.c2g__OwnerCompany__r.c2g__StateProvince__c}"/><br/>
            <apex:outputField value="{!relatedTo.c2g__OwnerCompany__r.c2g__ZipPostCode__c}"/><br/>
            <apex:outputField value="{!relatedTo.c2g__OwnerCompany__r.c2g__Country__c}"/><br/>
            <apex:outputText value="Phone: "/><apex:outputField value="{!relatedTo.c2g__OwnerCompany__r.c2g__Phone__c}"/><apex:outputText value=" Fax: "/><apex:outputField value="{!relatedTo.c2g__OwnerCompany__r.c2g__Fax__c}"/><br/><br/></small>
        </p>
        <p>
            <c2g:CODAFormatterController date="{!TODAY()}"/>
            <br/><br/>
            <apex:outputField value="{!relatedTo.c2g__Account__r.Name}"/>
            <br/><br/>
            Hello,
            <br/><br/>
            Please find attached a statement of your account with us. We would appreciate prompt payment of these items.
        </p>
        <br/><br/>
        <apex:dataTable value="{!relatedTo.c2g__MassEmailAccountLineItems__r}" var="line" border="1" cellpadding="3">
            <apex:column style="text-align:left"   headervalue="Document Type"      value="{!line.c2g__Transaction__r.c2g__TransactionType__c}"/>
            <apex:column style="text-align:left"   headervalue="Document Number"    value="{!line.c2g__Transaction__r.c2g__DocumentNumber__c}"/>
            <apex:column style="text-align:left"   headervalue="Document Reference" value="{!line.c2g__Transaction__r.c2g__DocumentReference__c}"/>
            <apex:column style="text-align:center" headervalue="Due Date"           value="{!line.c2g__DueDate__c}"/>

            <apex:column style="text-align:left"   headervalue="Currency"           value="{!line.c2g__TransactionLineItem__r.c2g__DocumentCurrency__r.Name}"/>


            <apex:column style="text-align:left"   headervalue="Debit"              value="{!IF(0 < line.c2g__DocumentOutstandingValue__c, 0,1)}" />
            <apex:column style="text-align:left"   headervalue="Credit"              value="{!line.c2g__DocumentOutstandingValue__c}"/>
        

<!--
            <apex:column style="text-align:left"   headervalue="Credit"             value="{!IF(line.c2g__DocumentOutstandingValue__c<0, ABS(line.c2g__DocumentOutstandingValue__c), 0)}" />
-->
        </apex:dataTable>

        <br/>
        <!--
            <apex:column style="text-align:right"  headervalue="Outstanding Amount"><c2g:CODAFormatterController number="{!IF(line.c2g__Transaction__r.c2g__TransactionType__c!='Journal',ABS(line.c2g__DocumentOutstandingValue__c),line.c2g__DocumentOutstandingValue__c)}" currency="{!line.c2g__TransactionLineItem__r.c2g__DocumentCurrency__r.Name}"/>
        -->
        <p>
            If you have any questions about this payment please do not hesitate to contact us.    
            <br/><br/>
            Thank you,
            <br/><br/>
            {!$User.FirstName} {!$User.LastName}
        </p>
    </messaging:htmlEmailBody>
</messaging:emailTemplate>
VikashVikash (Salesforce Developers) 
Hi,

I believe you have made the simple if statement complicated as it is reading 0,1 as parameters not as a results, Please make your IF statement simpler.

Thnaks
Vikash_SFDC
Tye HarrisonTye Harrison
Hi Vikash,

Thank you for your reply. Can you expand on your answer?

Below is the exact line that is causing trouble. All I'm trying to do is test if the value is less than zero. If so, display its absolute value. If not, return zero. This line gives me the Missing ')' error:
<apex:column style="text-align:left"   headervalue="Credit" value="{!IF(line.c2g__DocumentOutstandingValue__c<0, ABS(line.c2g__DocumentOutstandingValue__c), 0)}" />

The way I understand IF in templates is: IF(ConditionStatement, ConditionTrueValue, ConditionFalseValue) . If that is so, then my above code is: IF DocumentOutstandingValue < 0 THEN ABS of DocumentOutstandingValue ELSE 0 .