1

I am trying to use a utility method to format the date which is coming as a string. The method is a static method which accepts string as a parameter and returns a formatted date.

Utility.cls

public with sharing class Utility {
   public static String FormatDate(String s) {
        if(s != null || s!= '') {
            String[] dt = s.split('-');
            return dt[1]+'-'+dt[2]+'-'+dt[0];
        } else {
            return '';
        }

    }
}

Visualforce code:

<apex:page controller="ExportController" contentType="text/csv#{!fileName}.csv" 
        showHeader="false" sidebar="false" standardStylesheets="false">
    "Order #","Document Date","Purchase Order #","Sales Org","Amount","Currency","Products"
     <apex:repeat value="{!OpenSalesOrders}" var="oso">
        {!oso.OrderNo},"{!Utility.FormatDate(oso.DocumentDate)}","{!oso.PurchaseOrderNo}","{!oso.SalesOrg}","{!oso.Amount}","{!oso.Curren}","{!oso.Product}"
     </apex:repeat>
</apex:page>

Issue:

Unknown function Utility.FormatDate. Check spelling.

How to call a static method in an expression in visualforce page? Any ideas?

1 Answer 1

3

Unfortunately (and perhaps surprisingly) you can't in a Visualforce expression.

See this answer Rendering a Conditional Format for VisualForce Table Cell for the normal work-around of using a wrapper class.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .