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
BenjaminBBenjaminB 

Auto populate email template, add attachment and change record status

Hi guys,

 

I'm new to SFDC and I'm trying to achieve some automation for my co-workers.

What I've done is build a visual workflow that guides my co-workers through a wizard in which they choose a contract, fill in the required fields and then automatically submits their request for approval. So far so good.

 

Now for the second stage:

After I've approved the request, I create a document and upload it to the record and send an email to the person that requested the contract, the account owner (AO).

 

Now the account owner needs to 1)click "send an email" 2)pick the template 3) add the recipient's email address 4)add the email address of a couple of co-workers (always the same) 4) attach the document 5) click send 6) change the record status to "sent to partner".

 

The thing is that a lot of the information is always the same and should therefore not have to be entered manually. People tend to forget to add the co-workers to the cc, attach the document and most of all: they forget to change the status.

 

So I'm looking for a way to make something that populates everything (template, cc, attachment) and then sends the email when the user clicks and then finally changes the record status.

 

I have a couple of years of programming experience, but not with Java and I simply do not get how it works in SFDC. I tried to copy/paste the code of a plugin into the developer console and then saving it, but it wouldn't let me. This was for the first part to submit a record for approval. When I uploaded it with the ANT it did work, so the code was fine. What I'm trying to say is that I do understand (java) code, but I have no clue how to implement it into SFDC. 

 

I would be forever thankful if someone would give me an idiot proof guide on how to enter the code I need.

 

Thank you!

JayNicJayNic

Prepopulating the fields on the "send an email" screen is one step, and updating the record afterward is another.

 

Check the DOM ids of any of the fields on a "send an email" page and you can see their names and ids.

Notice that when you click the "send an email" button from the record, it passes a parameter called "p2_lkid" via the URL. The "lkid" part means "lookup id" (as far as I have experienced). 

 

The "cc" field has an id of "p4". So if I was to construct my url like so:

 

window.top.location = "/_ui/core/email/author/EmailAuthor?p2_lkid=003i0000008Oyat&rtype=003&p4=myemail@address.com";

 .. then I will end up with a value in the cc box.

 

Notice the "rtype" parameter? This is the Object prefix. In my example, I was coming from the "contact" detail page, so it passed the Contact object prefix "003". All Contact record ids start with 003, and the first three characters of any id in the system are the object prefix of that record. You may or may not need to pass that, but it would be a good idea to do it, or your users might get confused.

 

So that does it for all the fields on the page... The hidden one for the template id is cleverly named "template_id".

So you can pass a "template_id" to the page, and the email template will automatically fill out as well.

 

 

Now, for updating the record after the email is sent, this is another story. What I personally did was set a "saveURL" parameter in the url. This is the url that will be called when the user clicks "send" on the email screen. (Note that the "retURL" parameter is where the user goes after he hits cancel).

 

So I created a simple vf page that accepted a few simple parameters:

relatedToId - the record id we will update

field - the field name to update

value - the value to update the field

sObjectType - the name of the sObject

retURL - where the user will end up (most likely back at the record they came from)

 

My "saveURL" parameter redirected the user to the VF page with those parameters, where my controller consumed those parameters and used some dynamic apex to update the record and then redirected the user back to the ret url where they can see the record has been updated.

 

 

BenjaminBBenjaminB

Thank you very much for your reply! I´ll check if I can make it work like that. I´ll let you know asap if it worked out!