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
mikkamikka 

How to display the exact datetime value in our timezone in visualforce email template

 

Hi guys,

 

Kindly help me out... Im having problem converting the datetime value field in my time zone (GMT+08:00) Philippines Time (Asia/Manila) so that when datetime field is captured in email, the correct time settings will be displayed.

 

So far, here's what I've gone through:

1. Create a Formula text type field that will convert my datetime field.

    MID(TEXT( DueDate__c + _______ ), 12, 5)

 

    Problem is I dont know what value will be supplied in the blank field or the formula in converting time zone so that I may be able to get the exact date and time values same as what is displayed in SF.

 

Your help is really appreciated.

Thanks!!!

 

aballardaballard

You should be able to either use outputField to directly display the date field in the same way it would be displayed by the UI, or use apex:outputText with a format specification to format the data value in whatever form you want. 

mikkamikka

Thanks for replying Aballard. But how can I insert the apex:outputField component in my email message template below:

 

<messaging:emailTemplate subject="Activity {!relatedTo.Name} Due Date Notification" recipientType="User" relatedToType="Detailed_Activity__c">
<messaging:plainTextEmailBody >
Hi {!relatedTo.Assigned_To__r.Name},
This is to remind you that Activity: {!relatedTo.Name} is/was due on {!relatedTo.Due_Date__c}.
Kindly resolve as soon as possible.

-------------------------------------------------------------------------

Activity Information

Due Date: {!relatedTo.Due_Date__c}

aballardaballard

I don't know much about email templates, but can't you just use <apex:outputField value="{!relatedTo.Due_Date_c}"/>  ?

 

mikkamikka

Thanks but  I tried inserting the apex:outputText to email template but to no avail.
Please find below the different ways I inserted this:

a. <apex:outputText value="{!relatedTo.Due_Date__c}"/>
     
     output: date is still in GMT format

b. <apex:outputText value="{0,'dd/MM/yyyy HH:mm','Asia/Hong_Kong'}"/>
  <apex:param value="{!relatedTo.Due_Date__c}" />

    output: cannot read the outputText value


c. <apex:outputText value="{0,date,yyyy.MM.dd G 'at' HH:mm:ss z}"/>
  <apex:param value="{!relatedTo.Due_Date__c}" />

  output: cannot read the outputText value

 

Whie using outputField, it displays the following error message: <messaging:plainTextEmailBody> cannot contain <apex:outputField>.

 

Your help is really appreciated. Many many thanks!!!

aballardaballard

You're right; ouutputField is unfortunately not allowed in an email template.   

The only other approach I can think of would be to use a custom controller to format the datetime via apex.  

 

ShwetaSShwetaS

Hi,

 

Please try using the below format:

 

<apex:outputText value="{!day(relatedTo.Due_Date__c)}/{!month(relatedTo.Due_Date__c)}/{!year(relatedTo.Due_Date__c)}}">

 

Similarly, you can use other date functions to accomplish your requirement.

 

Shweta
Salesforce Developer Support

If my answer solved your question, please mark it solved so I can help as many community members as possible!