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
SK NallacheruvuSK Nallacheruvu 

How do I create a custom button on task/activities that dynamically determine the record id of the object it is on

Hi,
Is there a way to create a custom email button something in lines of below but this button can be on account, opportunity or lead. Is there a way to dynamically fetch the id of the record where the button is. For example if the below button is on Lead then the URL parameter should determine p3_lkid={!Lead.Id}, p4={!Lead.OwnerEmail}, etc. And also can it pass it over to the email template.

'/email/author/emailauthor.jsp?p2_lkid={!Contact.Id}&p4={!Opportunity.OwnerEmail}&rtype=003&p3_lkid={!Opportunity.Id}&template_id=00X30000000eCGt&retURL=/{!Opportunity.Id}'

Thank You
Mustafa JhabuawalaMustafa Jhabuawala
I think you can get the record ID dynamically using javascript.

For ex - 

JavaScript Code
var path = window.location.href;
//path contains --> https://mustafaj-dev-ed.lightning.force.com/one/one.app#/sObject/0012800001HZCFmAAP/view

var temp1 = path.split('sObject/');
//temp1 contains --> ["https://mustafaj-dev-ed.lightning.force.com/one/one.app#/", "0012800001HZCFmAAP/view"]

var temp2 = temp1[1].split('/');
//temp2 contains --> ["0012800001HZCFmAAP", "view"]

var recordID = temp2[0];

Let me know if this helps.
SK NallacheruvuSK Nallacheruvu

Thank u for the help mustafa. I dont see a way to use this javascript inside the email template. I am looking to get id dynamically in the template. For example say I have to use one common template for two different objects and its records say account(John Aaron) and lead(Stefen King) and in my template I want the name of the record where this email template is used. So here in my example if I use this template in an account I wanted it to display 'John Aaron' and if it is a lead want to display 'Stefen King'. How would I do that?