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
Christopher PennChristopher Penn 

Help needed: custom button to fire email template and update status

Hello all,

 

Long time lurker, first time poster. I'm trying to create a custom button for my lead view that will:

 

1. Fire an email template to a lead

2. Update a status field

3. Return the user to the lead view

 

Here's what I've got so far - it fires the template but does NOT update the status. Can someone point me in the right direction?

 

location.replace('/email/author/emailauthor.jsp?p2_lkid={!Lead.Id}&retURL=%2F{!Lead.Id}&template_id=00X40000001B4fY&{!URLFOR($Action.Lead.Edit, Lead.Id, [retURL=URLFOR($Action.Lead.View, Lead.Id), lea13_ileinner ="First email and call attempt made", save=1] )}')

 

Much appreciated!

 

Christopher S. Penn | cspenn@gmail.com
shillyershillyer

Take a look at the custom button example for the REQUIRESCRIPT function.

 

 

{!REQUIRESCRIPT("/soap/ajax/13.0/connection.js")}
var c = new sforce.SObject("Case");
c.id = "{!Case.Id}";
c.Status = "New";
result = sforce.connection.update([c]);
window.location.reload();

 

The example uses the Case object, but can be refactored for Lead.

 

Hope that helps,

Sati

Christopher PennChristopher Penn

The good news is that this refactored script now changes status.

 

The bad news is that this refactored script no longer sends mail.

 

Script:

 

location.replace('/email/author/emailauthor.jsp?p2_lkid={!Lead.Id}&retURL=%2F{!Lead.Id}&template_id=00X40000001B4fY')
{!REQUIRESCRIPT("/soap/ajax/13.0/connection.js")}
var c = new sforce.SObject("Lead");
c.id = "{!Lead.Id}";
c.Status = "First email and call attempt made";
result = sforce.connection.update([c]);
window.location.reload();
shillyershillyer

You could remove the portion to send an email, and then use workflow rules to send the email. So once the status field is updated, it will trigger an email alert to the lead using your desired template.

 

Hope that helps,

Sati

Christopher PennChristopher Penn

Ah, but the goal is to have one button do it all.

 

Is there any way based on your experience to fit that first line of code which previously worked into that large block of status stuff?

shillyershillyer

With workflow, one button will do it all. Once you click the button, the field will be updated. In the background, the workflow rule will catch the change and automatically send out the email alert. Give it a try and you'll see.

 

Best,

Sati

QuiqueprQuiquepr

True to a certain extent.  I appreciate the original intent as wf emails do not show on activity history for the record....this may be critical for the customer activity management and actions review on any object.  If you got it working would love to see the final code...

 

Regards,

Quique