Salesforce Stack Exchange is a question and answer site for Salesforce administrators, implementation experts, developers and anybody in-between. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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?

share|improve this question

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.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.