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
SK_SinghSK_Singh 

Update field in salesforce , when clicking on a Link sent in Email

I want to update a salefsorce field based upon User's Response. Basically a Link is sent To user via Email, if user clicks on that a link, then a field in salesforce should get updated, and display a VF Page message "Thanks for your response".

 

zachbarkleyzachbarkley

Hi SK_Singh,

A DML Statement on Page display is frowned apon by Salesforce.com and it is disallowed in the controller (Page Display) method in your Customer Controller Class however it's still technically possible via the VF page action.

 

As you have given us no actual sample use case, I will make one up for you.

 

USE CASE

 

I have an email that will be emailed to a customer with 2 links. Issue Solved and Issue Not Solved. I require this to update the field Status__c of a single record in my custom object Customer_Issue__c.

 

1) Create an email template on the Customer_Issue__c and merge the Id of the record into 2 links below.

 


2) Create a Visualforce Page named MyCustomVFPage and show this on your default website (Setup | Develop | Sites | Default website | Site Visualforce Pages )

 

VF Page

<apex:page id="Page" showHeader="false" controller="MyCustomVFPage_CTR" action="{!InitPage}" cache="false">
	<apex:form>
		Thank you for your custom.
	</apex:form>
</apex:page>

 

 

Apex Class

 

public class MyCustomVFPage_CTR {
	public String ObjectId {get;set;}
	public String ResponseCode {get;set;}
	public MyCustomVFPage_CTR () {
		ObjectId = ApexPages.currentPage().getParameters().get('ObjectId');
		ResponseCode = ApexPages.currentPage().getParameters().get('ResponseCode');
	}
	public PageReference InitPage() {
		List<Customer_Issue__c> CustomerIssues = [SELECT Id, Status__c FROM Customer_Issue__c WHERE Id=:ObjectId LIMIT 1];
		if(!CustomerIssues.IsEmpty()){
			CustomerIssues[0].Status__c = ResponseCode;
			UPDATE CustomerIssues;
		}
	}
}

 

HappyPics PhotographyHappyPics Photography

Hi zachbarkley, I wanted to impliment this feature into our Salesforce.
I currently have a workflow setup that when triggered it sends an email to my recipient (lookup list), This email template has account information and dates to book the job. I want the recipent to be able to click a link from that email template "Confirm" or "Cannot Do" and in turn, have this automatically update a field with the response.

CAn you please advise?
Thanks,
Clayton
 

Sumit Kumar Singh 9Sumit Kumar Singh 9

Hello HappyPics,
The above approach suggested by zachbarkley should work. 
If you have ant question then let me know. 


Thanks,
Sumit Kuamr Singh

HappyPics PhotographyHappyPics Photography
Thanks for getting back to me,
I am not a developer so I need to know how to go about implimenting this?
Igor OrackiIgor Oracki
Hey @Sumit Kumar Singh 9 could you please explain step by step how to implement this? I would like to use this function to close the case via email by clicking on "Solved" - I am not developer and need details. Thanks ! 
Sumit Kumar Singh 9Sumit Kumar Singh 9
Hello Igor, 

You need to create a site/ public page.
send the link in "href" attribule while sending the email.
When the user will click on the link it will get redirected to the "thank you" page , where update will be done.
If you have any further doubt , add me on skype sumit3887, I would be  happy to help you.

Thanks,
Sumit Kumar Singh
 
Rachel Sellers 4Rachel Sellers 4

Hi Sumit,

I have followed the process as above and everything seems to be working in my Sandbox but once I deployed to Production I am now getting the following error:

Authorization Required 

You must first log in or register before accessing this page. 
If you have forgotten your password, click Forgot Password to reset it.

As far as I can tell the Site User has all the right permission and field level security has been set to make the field editable by the profile. Do you have any suggestions as to why I might be getting this error?

Thanks,
 

Rach

Alex Von HasslerAlex Von Hassler
Hi, 

Thank you for posting the instructions. I'm trying to accomplish something very similar but ran into an issue with the apex class:

__________
"Error: Compile Error: Non-void method might not return a value or might have statement after a return statement. at line 10 column 9"
__________

I have the site, email template, and visual force page setup - no problems. 

Any help is greatly appreciated.

Thank you,
Alex
Alexandra KappAlexandra Kapp
Hi, 

was there any solution on this problem?

I run into the same problem: If I try to invoke the "update" of the contact right away when I open the URL, I get this error: 


Authorization Required 

You must first log in or register before accessing this page. 
If you have forgotten your password, click Forgot Password to reset it. 


If I place a button on the website, that starts the UPDATE method, it works just fine.

Kind regards
Alexandra