+ Start a Discussion
Kwalla25Kwalla25 

How to display name, not ID?

I am trying to create a VF email template that will be sent based off a date field on a custom object (Service_Plans__C_).  In the subject line, I'm trying to get it to display the name of the Opportunity that's related to the Service Plan.. but it displays the Opportunity ID, not the text name.

 

What should I use in place of {!relatedTo.Opportunity__c} to get the text name and not the ID? 

 

Service Plans is Master-Detail(Opportunity) if that matters.

 

<messaging:emailTemplate subject="Notification - Service Plan, {!relatedTo.Name}, for {!relatedTo.Opportunity__c} expires on {!relatedTo.Service_Plan_End_Date__c}" recipientType="User" relatedToType="Service_Plans__c">

 

Thanks!

 

K

Best Answer chosen by Admin (Salesforce Developers) 
WizradWizrad

You got this:

 

{!relatedTo.Opportunity__c}

 You want this:

 

{!relatedTo.Opportunity__r.Name}

 

All Answers

WizradWizrad

You got this:

 

{!relatedTo.Opportunity__c}

 You want this:

 

{!relatedTo.Opportunity__r.Name}

 

This was selected as the best answer
Kwalla25Kwalla25

I tried that before posting here.. and it did not work.    When I used {!relatedTo.Opportunity__r.Name} -- it did return a text result, but instead of the name of the Opportunity it provided the name of the service plan. 


As an example, if my Opportunity is called "Acme Products - Site 1" and the name of the service plan is "First Year Service Plan" -- I got "First Year Sevice Plan" as the result instead of the Opportunity name.

 

Should it not be r, but something else? 

 

I did {!relatedTo.Opportunity__c.Name}.. but that gave an error. 

 

Thanks,

 

K

WizradWizrad

Well, find out what field on Opporunity is housing what you think of as the Opportunity name, and when you do the proper syntax will be:

 

{!relatedTo.Opportunity__r.NameOfField__c}

 Where NameOfField__c is the name of the field that holds the name.