1

I have the Apex class code:

public class myController {
    public string url{
        get {
            if (this.url == null)
                this.url = System.URL.getSalesforceBaseUrl().getHost();
            return this.url; }
        set;
        }

}

I have Visualforcetemplate code for email alert in workflow rule:

<messaging:emailTemplate  recipientType="user"  relatedToType="order">
    <messaging:htmlEmailBody >
        <html>
        <body>
        <center>
            <p><br>

              Click on below link to go to this user setup:
              "**I want to use the instance here**/{!$User.Id}"
              </br></p>
             </center>
             </body>

            </html>
            </messaging:htmlEmailBody>
          </messaging:emailTemplate>

**How to write the visualforce component code for accessing the instance there?**in Visualforce page template in email alert in salesforce

Please anyone guide me for the Answer

I have tried :

<apex:component controller="myController" access="global">
<apex:value="{!myController}" var="s">
<!s.uri>
</apex:value>
</apex:component>

The above one is correct?

2
  • You want the URL to be shown on the VF page component? What is the use of email template and VF page?
    – Mahmood
    Commented Oct 26, 2016 at 12:25
  • No I am writing the Workflow rule, if the condition statisfied then the email should sent to the particular user with the help of email alert to carry the instance also
    – SFDC
    Commented Oct 26, 2016 at 12:27

1 Answer 1

1

Right now it is not possible, you can upvote the idea here. There is workaround, which I haven't tested myself,

  1. You can hard-code the org url and put it your email template
  2. You can create a custom label, and put the url in there, then call that custom label from within your email template (just to be controllable and less static than option 1)

Custom Label enter image description here

Then in your template use this merge field {!$Label.URL}/{! $User.Id} which results in the following:

https://[instancename].salesforce.com/[userid]

EDIT Another solution that is possible, it to use visualfore email templates and use vf component to have the url dynamically and call that component in vf email template. Example given below:

VF Component

<apex:component controller="myController" access="global">
  <p />
  <apex:outputLink id="urlString" value="{!url}/{!$User.Id}" >{!url}/{!$User.Id}</apex:outputLink>
</apex:component>

Name it "URL". You already have the controller.

Then use the above vf component in your email template , something like

<messaging:emailTemplate  recipientType="user"  relatedToType="order">
<messaging:htmlEmailBody >
   <html>
      <body>
         <center>
            <p>
               <br>
               Click on below link to go to this user setup:
               <c:URL/>/{!$User.Id}"
               </br>
            </p>
         </center>
      </body>
   </html>
</messaging:htmlEmailBody>

If you get into trouble or stuck, check this link out as well, as I haven't tested the above code myself.

20
  • how to place the value there in custom label,I have to get through the apex class then the value should be placed in custom label,Is it possible
    – SFDC
    Commented Oct 26, 2016 at 12:49
  • can you guide me for Visualforce component code for place the value there?@Mahmood,if we create using Custom label,if another user creates the record for them different url will be there for this reason i want visualforce component code
    – SFDC
    Commented Oct 26, 2016 at 12:52
  • please Dont Mistaken me @Mahmood
    – SFDC
    Commented Oct 26, 2016 at 12:54
  • guide me for the Custom component code @Mahmood
    – SFDC
    Commented Oct 26, 2016 at 13:00
  • In output Link is not Displaying , only text is displaying @Mahmood can you change the code in output link is dispalying
    – SFDC
    Commented Oct 26, 2016 at 13:32

You must log in to answer this question.

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