3

I am hitting a dead-end. I'm attempting to create a VF Email Template that will, based on an action of the recipient, update a record in Salesforce. However, I'm not sure if it really is possible since I'm having trouble finding anything to reference besides just creating the Email Template.

My use case: I need to have an External User be able to click on a Button that is within an email. This Button needs to send a message to Salesforce that it was pressed for the relating Case. We will then fire workflows on the Record after we have the variable passed into our Case saying the Button was clicked. This could potentially happen for both Customer Community Plus Users with licenses and then simply Contacts without a license.

Apex Controller

public class P2C {
    public String varCaseId {get; set;}
    public PageReference doVerify () {
       List<Case> updateCase = [SELECT Id FROM Case 
                              WHERE Id = :varCaseId
                                AND Status = 'Closed'];
if (!updateCase.isEmpty())
            {
   Case toupdateCase=updateCase[0];
   toupdateCase.Status='Updated Description';

            }

       }
    }

VF Page, not going for beauty right now... just functionality :-)

<apex:page standardController="P2C">
    <apex:commandButton action='doVerify' value='Submit'/>
</apex:page>

Right now I am getting some errors on save...

Apex Controller Error = Non-void method might not return a value or might have a statement after a return statement

VF Page Error = (under ) must occur between tags

  • 1
    I'm not full sure, what exactly are your requirement. What I understand, In the email received, recipient should get button. On click of it, he/she should be able to make update(Case record) in Salesforce ..rt ? If that is scenario.. this could be done without VF email template, albeit more easily with providing link instead of button. Please provide, from where mail will be sent? Also tell , whether recipient is gonna be someone with Salesforce user(having license) or someone external ? Will try to help accordingly. – curious_techy Jul 7 '15 at 3:51
  • I just updated the question to provide more information... but in short: This will be an external user without a license. I am assuming a link would be fine, but we would want that link to be 'housed' within a button as a URL? – David Litton Jul 7 '15 at 4:23
  • 1
    Since external user has to update case record. I'll suggest to make use of force.com 'site'. Create A VF page which is exposed through this force.com Site . This VF page could make an update to "Case" record. Also, In the mail sent to the Customer, we can provide link to this VF page. For this you might simply use HTML templates. But If you necessarily have to use Button, I think then you've to use Custom or VF template. If you find any problem in setting this up, I could help more in providing info about how to set up templates etc/ force.com sites etc.. – curious_techy Jul 7 '15 at 4:33
  • I understand how to create a Force.com site, and was attempting to go by this solution as well. I am getting held up on how I would pass this 'button' click from the email to the VF page exposed from the force.com Site. I was hitting a wall on that and thats why I moved to the Email Template route. Really I dont care what it updates, I can build a Flow or Workflow around it... I just need to have that VF page get populated with an alternate ID (to not reveal the SFDC one), and then to make an update on that Case record. – David Litton Jul 7 '15 at 4:38
  • Is that possible? To have the only click from the Customer be the click on the email? – David Litton Jul 7 '15 at 4:39
2

This mightn't provide answer to all of your queries. But since I've to provide code so writing here instead of writing comment . We'll continue to communicate here.

You've to use HTML template. But problem In that is simple HTML button code won't work, when email would be received.

So some modifications are needed, You've to use Links and give them appearance of Button something like this :

<table cellspacing="0" cellpadding="0"> <tr> 
<td align="center" width="300" height="40" bgcolor="#000091" style="-webkit-border-radius: 5px; -moz-border-radius: 5px; border-radius: 5px; color: #ffffff; display: block;">
<a href="<your force.com site link/<your VFPage>?id={!Case.Id}" style="font-size:16px; font-weight: bold; font-family: Helvetica, Arial, sans-serif; text-decoration: none; line-height:40px; width:100%; display:inline-block"><span style="color: #FFFFFF"> YOUR BUTTON NAME</span></a>
</td> 
</tr> </table>

Use this with other code for your template . This will send email with button. Revert in case of any issue

  • Thanks so much! I've gotten the Button to work. I also managed to get some code (javascript) to grab the {!Case.Id} that I am passing through. Is there a way to have this 'automatically' send the update to Salesforce? Is that done with a controller? I tried to get it via Flow, but I need to have the Flow in a VF Page for it to actually work... so that option was short lived unless I can get it working. – David Litton Jul 7 '15 at 15:48

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.