I have tried appending __c and __r as other threads have suggested, but I haven't had any luck yet--maybe I'm reading their advice incorrectly. I'm working on my first visualforce email template and when I attempt saving it I get an error message: "Error: Invalid field Display_Name for SObject Event"

The little bit of code that generates it is:

<messaging:emailTemplate subject="You Are Registered!" recipientType="Contact" relatedToType="Event">
<messaging:plainTextEmailBody >
Thank you for registering for our {!relatedTo.Display_Name}.

What can I do to have it recognized as a valid field?

  • Can you confirm there is a field on Contact whose API Name is Display_Name__c? – Adrian Larson Nov 3 '16 at 16:12
  • No; that field is on Event, the "relatedToType" – bblohowiak Nov 3 '16 at 16:44
  • Right, Event. That's what I meant. Can you confirm the exact API Name does, in fact, exist? – Adrian Larson Nov 3 '16 at 16:45
  • The exact API Name is "EventApi__Display_Name__c." I replaced it and got pretty much the same error message, "Invalid field EventApi__Display_Name__c for SObject Event" – bblohowiak Nov 3 '16 at 17:39
  • 1
    I realized that I needed to get the API Name for the custom object that was the relatedToType correct: "relatedToType="EventApi__Event__c"". That helped! – bblohowiak Nov 3 '16 at 20:37

Every API Name must be exact. You should be able to run the following snippet in Execute Anonymous by putting the two together if you use relatedToType="MyObject__c" and {!relatedTo.MyField__c}:

SObjectField mergeField = MyObject__c.MyField__c;

In this case you need to double check Event and Display_Name__c.

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.