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
scottious888scottious888 

Email link back to custom object

I have a visualforce email template which looks like so:



<messaging:emailTemplate subject="A High Touch record has been assigned to you" recipientType="User" relatedToType="Touch__c">
<messaging:plainTextEmailBody>

The following High Touch record has been assigned to you.

{!recipient.Name}
Account: {!relatedTo.Account__c}
Type: {!relatedTo.Type__c}
Contact Name: {!relatedTo.Contact_Name__c}
Contact Phone: {!relatedTo.Contact_Phone__c}
Contact Email: {!relatedTo.Contact_Email__c}
Company News: {!relatedTo.Company_News__c}
Notes: {!relatedTo.Notes__c}

</messaging:plainTextEmailBody>
</messaging:emailTemplate>


I want to add a link back to view the custom object record but cannot figure out what to use.

I tried {!Touch__c.Link} (among many other things) but this does not work. Any suggestions?
shillyershillyer

I run into this before, it doesn't appear that Visualforce Templates have a "detail link" merge field like you find in the other email templates, so you can do something like this:

Code:
If you plan to use this just in your org (substitute na1 for your org instance):
https://na1.salesforce.com/{!relatedTo.id}

If you plan to package/share this and you want it more generic:
https://login.salesforce.com/—startURL=/{!relatedTo.id}


 
Hope that helps,

Sati

scottious888scottious888
That's great shillyer!

I was after a generic solution as the server name will change once I move from developer account to production.

A pity you still have to login though even if you are logged in already.

BTW i had to change the - to a ?
https://login.salesforce.com/?startURL=/{!relatedTo.id}

Many thanks,

Scott.
dchasmandchasman
VF Email Templates are VF based and as such have access to the full power of VF formulas and many of the standard components - somrthing like this this is what you really want:

Code:
<apex:outputLink value="{!urlFor($Action.Account.View, relatedTo.account__c.id)}">
{!relatedTo.account__c.name}
</apex:outputLink>



BTW if you find yourself hard coding urls etc you can be almost 99% certain that is not the correct way to go and that there is a supported solution...
TehNrdTehNrd
Doug,

Is this part of the 1%.... http://community.salesforce.com/sforce/board/message?board.id=Visualforce&message.id=5054 ?

From the moment I created that I knew it wasn't a good idea but I can't figure out the correct way to do this.


Message Edited by TehNrd on 01-15-2009 09:45 AM
dchasmandchasman
This was a question about VF Email Templates - can't even use apex code in them yet (no support for extensions or custom controllers - yet). There is currently no analog for urlFor() from formulas in apex code (not yet at least). Have you tried using a component and assignTo to push the result of a urlFor() based expression into a custom component controller to leverage formulas long standing urlFor() support?
scottious888scottious888
Forgive my ignorance, but i'm really new to force.com. When you mentioned the following code above (I altered to suit as Account is a related object).
Code:
<apex:outputLink value="{!urlFor($Action.Account.View, relatedTo.Account__r.id)}">
  {!relatedTo.Account__r.name}
</apex:outputLink>

I tried this in the VF Email Template but it came back with an error:

Error occurred trying to load the template for preview: Invalid parameter for function URLFOR. Please try editing your markup to correct the problem.


So, I tried adding the code into a component but it did not recognise the relatedTo object. Where am I going wrong?

Thanks.
TehNrdTehNrd
I believe the above code was just an example. Since you want to view the touch object it would be something like this:

Code:
<apex:outputLink value="{!urlFor($Action.Touch__c.View, relatedTo.Touch__c.id)}">
  {!relatedTo.Touch__c.name}
</apex:outputLink>

 

EchoEchoEchoEcho

TehNrd wrote:
I believe the above code was just an example. Since you want to view the touch object it would be something like this:

Code:
<apex:outputLink value="{!urlFor($Action.Touch__c.View, relatedTo.Touch__c.id)}">
{!relatedTo.Touch__c.name}
</apex:outputLink>

 


 
This doesn't actually work either. urlFor creates a relative link, so the URL generated doesn't include the domain name.