0

When I include the following code inside the "subject" of my visualforce email template I can't use "send test and verify merge fields" - the message 'The template does not have a controller that can be selected for preview.' appears.


{! IF( AND(relatedTo.event__r.start_date__c != null, relatedTo.event__r.end_date__c != null, 
(DAY(relatedTo.event__r.start_date__c) > DAY(relatedTo.event__r.end_date__c))), 
CASE(MONTH(relatedTo.event__r.start_date__c),
 1, ' January',
 2, ' February',
 3, ' March',
 4, ' April',
 5, ' May',
 6, ' June',
 7, ' July',
 8, ' August',
 9, ' September',
 10, ' October',
 11, ' November',
 12, ' December',
 ''
)
,'')}

In the email subject I want to get:

Confirmation - Event, 14-15 September, City, Country 

(if event date is 14-15 september)

OR if the dates go over the month 29 Sep - 1 October

Confirmation - Event, 29 September - 1 October, City, County.

Full Code (only the above seems to be causing an issue):

<messaging:emailTemplate subject="Confirmation - {! relatedTo.event__r.name }, 
{! DAY(relatedTo.event__r.start_date__c)}
{! IF( AND(relatedTo.event__r.start_date__c != null, relatedTo.event__r.end_date__c != null, 
(DAY(relatedTo.event__r.start_date__c) > DAY(relatedTo.event__r.end_date__c))), 
CASE(MONTH(relatedTo.event__r.start_date__c),
 1, ' January',
 2, ' February',
 3, ' March',
 4, ' April',
 5, ' May',
 6, ' June',
 7, ' July',
 8, ' August',
 9, ' September',
 10, ' October',
 11, ' November',
 12, ' December',
 ''
)
,'')}

-{!DAY(relatedTo.event__r._end_date__c)} 
{!CASE( MONTH(relatedTo.event__r.end_date__c),
 1, 'January',
 2, 'February',
 3, 'March',
 4, 'April',
 5, 'May',
 6, 'June',
 7, 'July',
 8, 'August',
 9, 'September',
 10, 'October',
 11, 'November',
 12, 'December',
 ''
)
}, 
{! relatedTo.event__r.city__c },
{! relatedTo.event__r.country__c }
" recipientType="User" relatedToType="Participant__c" >
  • what object is relatedTo ? – cropredy Oct 10 '19 at 20:27
2

There seems to be something a bit funky about date comparison, and possibly short circuit evaluation, when you put that formula into the subject - (works fine in body of email).

If you just put in

IF( DAY(relatedTo.date_field_1__c) >
DAY(relatedTo.date_field_2__c), 'good', 'bad')

It gives error -

The value 'null' is not valid for operator '>'.

With the null check in the AND()

IF(AND(relatedTo.date_field_1__c != null,
relatedTo.date_field_2__c != null,
DAY(relatedTo.date_field_1__c) >
DAY(relatedTo.date_field_2__c)), 'good', 'bad')

Works fine in body, but when in subject it gives the above error.

If you put in:

IF(AND(false, DAY(relatedTo.date_field_1__c) >
DAY(relatedTo.date_field_2__c)), 'good', 'bad') 

You still get the error which suggests to me it's something to do with the day comparison getting evaluated somewhere.

One solution - create a checkbox formula field on the object that compares the day value of the two date fields

DAY(date_field_1__c) > DAY(date_field_2__c)

and reference that in the visualforce IF formula

|improve this answer|||||
  • I had a hard time believing this so I tried it myself and can confirm. Thanks for doing the research. – cropredy Oct 12 '19 at 21:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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