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
David OvellaDavid Ovella 

​Send an email using a button in a custom object

Hello, can anyone help me pls?

I have an object called "OT__c" and in it there's a field called email__c which belong to the client, and I want to know,
how can I create a button that when I click on it sends some information of the object OT__c to the email of the client?

 
Best Answer chosen by David Ovella
SonamSonam (Salesforce Developers) 
Try the following code for the javascript- I've tested and its working on my ORG:

location.replace('/email/author/emailauthor.jsp?retURL=/{!Case.Id}&p3_lkid={!Case.Id}&rtype=003&p2_lkid={!Case.ContactId}&template_id=00X90000000EScf&p24={!Case.email_to__c}');

All Answers

SonamSonam (Salesforce Developers) 
The below link shows hwo you can setup the email button on the object - https://success.salesforce.com/ideaview?id=087300000006tqzAAA

You need to have the value of the email__c field passed in as a parameter and that should help you send the email - the only thing to consider here is the link talks about a specific email template that can be sent - do you have a similar requirement?
David OvellaDavid Ovella
thanks Sonam for responding.
And yes, I have an specific email template that I want to send but I'm new in this and I don't know how to passed the value of the email__c as a parameter? by any chance do yo have any example?
SonamSonam (Salesforce Developers) 
Try the following code for the javascript- I've tested and its working on my ORG:

location.replace('/email/author/emailauthor.jsp?retURL=/{!Case.Id}&p3_lkid={!Case.Id}&rtype=003&p2_lkid={!Case.ContactId}&template_id=00X90000000EScf&p24={!Case.email_to__c}');
This was selected as the best answer
David OvellaDavid Ovella
thanks Sonam, It works great
David OvellaDavid Ovella

Hello Sonam, can I bother you with another question?

The button works perfectly but when I click on it some field that are in my email template doesn't show

For example:
                                                     {!OT__c.Date__c}

Good Morning  {!OT__c.Client_Name__c}


do you know why?

and thank you.
David.
SonamSonam (Salesforce Developers) 
Interesting..can you please confirm you are using this reference field in the URL:
 p3_lkid={!CaseOT__c.Id}
Are the other merge fields working?
David OvellaDavid Ovella
I'm using:
location.replace('/_ui/core/email/author/EmailAuthor?p24={!OT__c.Email_Client__c}&retURL=%2F{!OT__c.Id}&template_id=00X17000000M3co');

when I tried to use p3_lkid= it appeared this error:
The value of the "p3_lkid" parameter contains a character that is not allowed or the value exceeds the maximum allowed length. Remove the character from the parameter value or reduce the value length and resubmit. If the error still persists, report it to our Customer Support team. Provide the URL of the page you were requesting as well as any other related information.

the values that I used for p3_lkid= were: 
{!OT__c.Id} error
{!OT__c.Name} error
{!CaseOT__c.Id}  can't save
{!Case.OT__c.Id} can't save
SonamSonam (Salesforce Developers) 
Tried the same on my setup and seems to work:

can you please confirm you are using the syntax as follows:
ocation.replace('/_ui/core/email/author/EmailAuthor?p24={!OT__c.Email_Client__c}&p3_lkid={!OT__c.Id}&retURL=%2F{!OT__c.Id}&template_id=00X17000000M3co');
Ganesh BollinaGanesh Bollina
@Sonam,
 I have a requirement where i need to send an email to a particular email address(just one) when you click on a button on Quote Object. Can you please help me with the work around. Thanks in advance