2

I am writing trigger to send email to task owner after task got created.In the mail i was sending recordId as a plain text.But i was trying is there any way to make the id as a link to the related record in salesforce.

the mail should be like

  Hello {task.OwnerId},

    A new {task.Id} was allocated for you.

Thanks,
User.Name.

this was a custom html mail here i am not using any html template.So i was wondering is there any way to do it in custom way like in standard html template we use {task.Link}

4
  • possible duplicate of Detail page link under email template
    – cropredy
    Jul 2, 2015 at 18:56
  • While it may be a duplicate of something, it doesn't appear to be a duplicate of the linked question.
    – sfdcfox
    Jul 2, 2015 at 19:38
  • @crop1645 i was asking how to get this in apex but the link given is about email templates.. i might be wrong , thanks
    – Rajasekhar
    Jul 3, 2015 at 5:45
  • sorry - i thought you were asking about templates - metadaddy below has the apex answer
    – cropredy
    Jul 4, 2015 at 3:57

1 Answer 1

5

If you want a link in a text email template, you can use https://login.salesforce.com/{task.Id} (or https://test.salesforce.com/{task.Id} in a sandbox) - if the user is already logged in, this will go straight to the Task; otherwise, it will take them to the Task via the login page. It also has the benefit of avoiding a direct reference to the instance (e.g. na15.salesforce.com), which can cause problems in the long term.

If you're generating the email text from Apex, you can use URL.getSalesforceBaseUrl().toExternalForm() + '/' + task.Id to achieve the same end.

4
  • Won't this break for sandboxes though?
    – Adrian Larson
    Jul 2, 2015 at 21:06
  • Added the sandbox login link. I can't think of a generic way to do this that will work across both.
    – metadaddy
    Jul 2, 2015 at 21:08
  • 1
    Since it's apex you could just get it programmatically with URL.getSalesforceBaseUrl().toExternalForm().
    – Adrian Larson
    Jul 2, 2015 at 21:11
  • Question seemed to be about templates, but I added a note for Apex. Thanks!
    – metadaddy
    Jul 2, 2015 at 21:22

You must log in to answer this question.

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