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
Steve HuseSteve Huse 

Custom button to email a lead

Hi all,

 

We use web-to-lead, which generates lots of enquiries from outside of our area of coverage (despite our area of coverage being clearly stipulated on all of our contact pages!).

 

Out of courtesy, before deleting a lead who's outside of our area, I'd like a button (in Leads) that sends them a templated email saying 'Thanks for your enquiry but sorry, you are outside of our coverage area (blah blah)'.

 

I'm fine with creating custom buttons, but could use some code to create and send the email.  Ideally the email will contain a couple of lead mergefields and be created and sent on a single click (I don't need to review it).

 

I'm conversant with creating email templates.

 

Can anyone give me some guidance as to the best button code to pull this action together please?

 

Thanks in advance.


Steve

 

PS:  It would be even better if the button could email the lead and then delete them?

Baktash H.Baktash H.

Thats easy. The Button redirects you to a VF, it may look like this:

Button:

/apex/myVFPage?id={!Lead.ID}

 

VF:
<apex:page controller="leadMailController" action={!sendMail}> 

</apex:page>

 

The class leadMailController has a function sendMail, which does a few things.

1. Get the Lead with the id from the URL.

2. Create a mail.

3. Send the mail.

4. Delete the lead.

5. redirect you to any page you want ( not to the lead, because its deleted ;) )

Steve HuseSteve Huse

Thanks Baktash, but sorry - I should have mentioned that we're using Professional Edition (with Workflow and API bolted on), so don't have Apex available to us.

 

Any other solutions that don't require Apex?