8

I have tried this code for custom button for single click email sending. Unfortunately it is not working and returns an error. Could anyone tell me what I am doing wrong and correct me please.

Thank you.

location.replace('/email/author/emailauthor.jsp retURL=/{!Opportunity.Id}&p24="xxx@gmail.com,xxxx@uh.edu"&template_id="00Xj0000000J8sI"&p3_lkid={!Opportunity.Id}&p3={!Opportunity.Name}&p26={!User.Email}&p5="xyz@gmail.com"&save=0');

enter image description here enter image description here

  • 1
    Try removing the "" for the Id and try ! – Sanjay Jun 5 '15 at 17:54
  • @Sanjay .... That worked. But I have to enter "To Address " email id in the code above. How can I enter that and where can I? Also with this code will it be able send the email without any further user intervention? – SFDC_BigDog Jun 5 '15 at 18:01
  • could you share the URL you're using now after removing "" – Sanjay Jun 5 '15 at 18:21
  • @Sanjay location.replace('/email/author/emailauthor.jsp?retURL=/{!Opportunity.Id}&p24= varunreddypenna@gmail.com,v.reddy@thegordiangroup.com&template_id= 00Xj0000000J8sI &p3_lkid={!Opportunity.Id}&p3={!Opportunity.Name}&p26={!User.Email}&p5=penna.janareddy@gmail.com &save =0'); – SFDC_BigDog Jun 5 '15 at 18:24
  • try save=1 and can you test and tell me what's happening – Sanjay Jun 5 '15 at 18:27
11

The email author URL should look like below. Out of all the parameters I would always use "p3_lkid" and "retURL". Rest of the parameters are optional. Let's break this down:

_ui/core/email/author/EmailAuthor?p3_lkid=001E000000CVCF7&retURL=%2F001E000000CVCF7&p2_lkid=003180000066S1e&p4=abc@cc.com&p5=abc@bcc.com;xyz@bcc.com&p6=Hello World&p23=Nice to meet you&p24=asd@additional.com&template_id=

p3_lkid = "Related To" Id. Based on the Id, Salesforce will automatically select the object and record. This Id will be used to populate the merge field, if you are also using a template.

retURL = Return URL if cancel is pressed. Followed by %2F.

p2_lkid = Contact Id. Use to populate "To" field. It automatically fetches the email of this contact to send email. Also, populates the contact merge fields, if used.

p4 = CC

p5 = BCC. I passed two emails separated by semicolons to keep two different people in the loop. Same goes with CC field.

p6 = Subject of this email.

p23 = Email body.

p24 = Additional emails.

template_id = Id of template you are going to use. This template should contain merge fields of the same object as p3_lkid. No need to pass p6 and p23, if the template already handles them.

Now, coming to your case. There is no need to keep the behavior as javascript. URL behavior could have also met your requirement. Hence, I am modifying your code considering the behavior as URL.

/_ui/core/email/author/EmailAuthor?retURL=%2F{!Opportunity.Id}&p24=varunreddypenna@gmail.com;v.reddy@thegordiangroup.com&template_id=00Xj0000000J8sI&p3_lkid={!Opportunity.Id}&p5=penna.janareddy@gmail.com

Removed P3 - If you're using p3_lkid, then no use to do this.

Removed p26 - NOT sure what you trying to achieve here.

Used semi-colons between emails.

NO need to use location.replace and inverted commas. Simply copy paste the url with behavior as "URL".

Also, you should use merge field for "p24" by creating formula field for that.

To add more parameters, please see the structure above.

PS:- It would better if you query the template based on its developer name. However, then you will have to execute the button as javascript.

| improve this answer | |
2

Also you can add "&new_template=1" if you want attachments from email templates to show up.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.