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}
Best Answer
If you want a link in a text email template, you can use
https://login.salesforce.com/{task.Id}
(orhttps://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.