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
MC AdminMC Admin 

Issues with auto-populate email address in emails sent from custom object

We created a custom button to have the email address(es) in the custom object auto-populate in the email using the following formula:
 
location.replace('/_ui/core/email/author/EmailAuthor?p24={!Client__c.Email_1__c}&p4={!Client__c.Email_2__c}&p5=support@companyname.com');
 
The email addresses are populating correctly, but we are having the following issues and would very much appreciate some help:
 
1. The information that is supposed to auto-fill in the email templates (i.e.; Dear {!Client__c.First_Name__c}, is now blank when we select the template.

2. When we click the custom button to send and email and then click “Cancel” it takes us back to the home page, instead of the client record

3. When we click the custom button to send and email and then click “Send” it takes us back to the home page, instead of the client record
 
Also, we recently received an email from SalesForce stating the following:
“Salesforce will block JavaScript execution in hyperlink formula fields via a phased approach. Salesforce defines these fields as custom hyperlink formula fields starting with the string "javascript:"  Is this going to interfere with the custom button formula shown above?
 
Thanks in advance.
 
Best Answer chosen by MC Admin
MC AdminMC Admin
Hi Maharaja C,

Adding retURL=%2F{!Client__c.Id} to the formula solved issues 2 and 3 above.  Now the user is returned to the Client record after clicking "Cancel" or "Send."  Thank you!

FYI... We added p3_lkid={!Client__c.Id} to the formula and that solved issue 1 above.  Now all merge fields are pulling in correctly and the email shows in the Activity History section after it is sent.

I have one more question:
We have a custom object (API Name: Babies__c) that is related to the custom object Client referred to above.  The related Client record contains the email address fields.  We want to be able to send some emails from the Babies record and have the email addresses from the related Client record auto-populate in the email.

We created a custom button in the Babies record and tried the following formulas, but it is not pulling the email addresses from the related Client record:

location.replace('/_ui/core/email/author/EmailAuthor?p3_lkid={!Babies__c.Id}&retURL=%2F{!Babies__c.Id}&p24={!Client__c.Email_1__c}&p4={!Client__c.Email_2__c}')

location.replace('/_ui/core/email/author/EmailAuthor?p3_lkid={!Babies__c.ClientId__c}&retURL=%2F{!Babies__c.Id}&p24={!Client__c.Email_1__c}&p4={!Client__c.Email_2__c}')

Any ideas on how to solve this would be much appreciated.

Thanks again.

All Answers

Maharajan CMaharajan C
Hi MC,

You don't have the return url in your formula:

Change like below use the retURL parameter :

location.replace('/_ui/core/email/author/EmailAuthor?retURL=%2F{!Client__c.Id}&p24={!Client__c.Email_1__c}&p4={!Client__c.Email_2__c}&p5=support@companyname.com')

OR

location.replace('/_ui/core/email/author/EmailAuthor?retURL=/{!Client__c.Id}&p24={!Client__c.Email_1__c}&p4={!Client__c.Email_2__c}&p5=support@companyname.com')

Use the Visual force Email template to populate the field from the custom object may be it will solve you field population issue or use the template people suggested in the below links.

Refer the below Links completely:

http://www.salesforceben.com/salesforce-email-url-hack-tutorial/

http://thewizardnews.com/2014/01/30/url-hack-revisted-auto-select-email-template-with-custom-button/

https://success.salesforce.com/answers?id=90630000000gtNyAAI


Also, we recently received an email from SalesForce stating the following:
“Salesforce will block JavaScript execution in hyperlink formula fields via a phased approach. Salesforce defines these fields as custom hyperlink formula fields starting with the string "javascript:"  Is this going to interfere with the custom button formula shown above?

For the above one refer the Salesforce Document: https://help.salesforce.com/articleView?id=000249336&type=1

Can you please Let me know if it works or not and also If you face any problems!!!

If it works don't forget to mark this as a best answer!!!

Thanks,
​Raj
MC AdminMC Admin
Hi Maharaja C,

Adding retURL=%2F{!Client__c.Id} to the formula solved issues 2 and 3 above.  Now the user is returned to the Client record after clicking "Cancel" or "Send."  Thank you!

FYI... We added p3_lkid={!Client__c.Id} to the formula and that solved issue 1 above.  Now all merge fields are pulling in correctly and the email shows in the Activity History section after it is sent.

I have one more question:
We have a custom object (API Name: Babies__c) that is related to the custom object Client referred to above.  The related Client record contains the email address fields.  We want to be able to send some emails from the Babies record and have the email addresses from the related Client record auto-populate in the email.

We created a custom button in the Babies record and tried the following formulas, but it is not pulling the email addresses from the related Client record:

location.replace('/_ui/core/email/author/EmailAuthor?p3_lkid={!Babies__c.Id}&retURL=%2F{!Babies__c.Id}&p24={!Client__c.Email_1__c}&p4={!Client__c.Email_2__c}')

location.replace('/_ui/core/email/author/EmailAuthor?p3_lkid={!Babies__c.ClientId__c}&retURL=%2F{!Babies__c.Id}&p24={!Client__c.Email_1__c}&p4={!Client__c.Email_2__c}')

Any ideas on how to solve this would be much appreciated.

Thanks again.
This was selected as the best answer
MC AdminMC Admin
Thanks Raj.

We get the following syntax error:
Error: Field Babies__r.Client__r.Email_1__c does not exist. Check spelling.
Maharajan CMaharajan C
Sorry my suggestion is completley wrong!!!

Did you got the solution?

Try the formula field to get the client email in Babies record via Lookup then use that in Button.

Thanks,
Raj
MC AdminMC Admin
Thanks Raj.

We wound up using a work-around (it may be what you were suggesting?).  We created fields in the Babies record with a formula that pulls in the email addresses from the related Client record and then used those fields in the Babies record for the formula.
MC AdminMC Admin
Thanks again Raj.  I appreciate your help with this.