0

I am struggling with something I think should not be difficult but I am not able to figure out, my date field display as the below screenshot.

enter image description here

My aim is to remove from the template the characters 00:00:00 GMT 2020 The field is date type, and I am sending to the visualforce component in the following way, then the visualforce component read the field as String

Email Template Content:

<messaging:emailTemplate recipientType="User" relatedToType="SBQQ__Quote__c" subject="Quote {!relatedTo.Name} requires Trial Request">   
    
<messaging:htmlEmailBody > 

     <c:CPQComponent quoteId="{!relatedTo.id}" accountName="{!relatedTo.SBQQ__Account__r.Name}" 
                                    quoteNetAmount="{!relatedTo.SBQQ__NetAmount__c}" 
                                    salesRep="{!relatedTo.SBQQ__SalesRep__r.Name}" 
                                    recipientName="{!recipient.name}" 
                                    primaryContact="{!relatedTo.SBQQ__PrimaryContact__c}" 
                                    trialRequestShipDate="{!relatedTo.Requested_Ship_Date__c}" 
                                    />                        
</messaging:htmlEmailBody>
</messaging:emailTemplate>

Visualforce Component Portion Code:

<apex:component controller="CPQ_CSTrialRequestController" access="global">
<apex:attribute name ="trialRequestShipDate" type="String" description="Trial Requested Ship Date" assignTo="{!quote_TrialRequestShipDate}"/>
<font color="#58595b" face="Arial,Verdana,Trebuchet MS,Helvetica,sans-serif" style="font-size:16px; line-height: 24px;">{!quote_TrialStartDate}</font></td>

Do you recommend me other approach?

Thanks!

6
  • is Requested_Ship_Date__c really a Text data type and not a Date datatype?
    – cropredy
    Commented Jun 16, 2020 at 15:55
  • It is a Date datatype
    – l13
    Commented Jun 16, 2020 at 15:56
  • Then the component data type should be Date and you can use standard date formatting via apex:Param to get what you need
    – cropredy
    Commented Jun 16, 2020 at 15:58
  • Thank you for your support. @cropredy. I changed to Date but I am facing now the following error: Incorrect parameter type for operator '-'. Expected Number, Date, DateTime, received Text. I think i faced before I tried with Date type
    – l13
    Commented Jun 16, 2020 at 16:25
  • your component controller property called trialRequestShipDate needs to use Date as well; I presume you know about VF formatting dates using outputText
    – cropredy
    Commented Jun 16, 2020 at 17:28

1 Answer 1

1

Here is your issue:

The field passed to the VF component is of type Date

trialRequestShipDate="{!relatedTo.Requested_Ship_Date__c}

The component defines it as type String

<apex:attribute name ="trialRequestShipDate" type="String" 

And the VF Component controller would also have been defined as type String

public String trialRequestShipDate {get; set;}

To fix, both the <apex:attribute> and the VF component property should be of type Date

You'll then be able to easily format the value as you want using <apex:outputText> using this VF field formatting reference

You must log in to answer this question.

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