+ Start a Discussion
Alex Von HasslerAlex Von Hassler 

How can I update a field value by clicking on a link sent in an email?

Hi, I would like to update a field value when a user clicks on a link or button on a email sent out by salesforce. 

We have a workflow that sends out automatic reminders about certain jobs. I would like to setup a second workflow that sends an email 2 days later with a button or link (e.g. "Job completed? Yes, No?") for the user to click on. That button or link should then update a field value in salesforce to "Job completed" or "Job cannot be completed". It doesn't matter if it's a picklist or text field, - I just can't figure out a way to update a field by clicking on a button/link in an email. 

I greatly appreciate any help. 

Alex
Best Answer chosen by Alex Von Hassler
YogeshMoreYogeshMore
Alex,

You can achieve this requirement by using Salesforce Site. For this you have to create site, visualforc page, apex class and email template. Go through the following steps.
  • Firstly you have to create site. (Setup | Develop | Sites).
  • Then create Visualforce page and apex class to update the record.
    //Page Name - updateJobStatus
    
    //Page Code – 
    <apex:page controller="updateJobStatus" action="{!updateRec}" cache="false">
    	<apex:form>
    		Thank you for your custom.
    	</apex:form>
    </apex:page>
     
    //Apex class code–
    public class updateJobStatus{
    
    	public String recId {get;set;}
    	public String isJobCompleted {get;set;}
    
    	public updateJobStatus() {
    		recId = ApexPages.currentPage().getParameters().get('recId');
    		isJobCompleted = ApexPages.currentPage().getParameters().get('isJobCompleted');
    	}
    	public PageReference updateRec() {
    		
    		objectAPIName obj = new objectAPIName();
    		obj.Id = recId;
    		obj.fieldAPIName = isJobCompleted;
    		update obj;
    	}
    }
  • Then add created visualforce page in to site Visualforce Page (Setup | Develop | Sites | Default website | Site Visualforce Pages )
  • Create email template and add site link in email with parameters. refer following links​.
  •  
    http://mydomain.force.com/ updateJobStatus? recId =a1cN0000000Vr6R& isJobCompleted Yes
    http://mydomain.force.com/ updateJobStatus? recId =a1cN0000000Vr6R& isJobCompleted =No
     
     
    When user click on given link then visualforce page will open and record will update automatically.
     
    Regards,
    Yogesh More
    more.yogesh422@gmail.com || Skype:-yogesh.more44

All Answers

YogeshMoreYogeshMore
Hello Alex,
 
You can create custom button/link and execute java-script code to update specified field.
For your reference you use following code.
 
{!REQUIRESCRIPT("/soap/ajax/29.0/connection.js")}
{!REQUIRESCRIPT("/soap/ajax/29.0/apex.js")}
 
  var varName = new sforce.SObject("ObjectAPIName");
  varName.Id = '{!ObjectAPIName.Id}';
  varName.YourFieldAPIName = 'Job completed';
  var result = sforce.connection.update([varName]);
  window.location.reload();

Let us know if it helps you.
 
Regards,
Yogesh More
more.yogesh422@gmail.com || Skype:-yogesh.more44
 
Alex Von HasslerAlex Von Hassler
Yogesh, 

Thank you for helping out. This button works great within salesforce, but I was hoping to send out a link in an email that can update a field.

The user shouldn't even have to be in salesforce for this. 

Thank you,
Alex
YogeshMoreYogeshMore
Alex,

You can achieve this requirement by using Salesforce Site. For this you have to create site, visualforc page, apex class and email template. Go through the following steps.
  • Firstly you have to create site. (Setup | Develop | Sites).
  • Then create Visualforce page and apex class to update the record.
    //Page Name - updateJobStatus
    
    //Page Code – 
    <apex:page controller="updateJobStatus" action="{!updateRec}" cache="false">
    	<apex:form>
    		Thank you for your custom.
    	</apex:form>
    </apex:page>
     
    //Apex class code–
    public class updateJobStatus{
    
    	public String recId {get;set;}
    	public String isJobCompleted {get;set;}
    
    	public updateJobStatus() {
    		recId = ApexPages.currentPage().getParameters().get('recId');
    		isJobCompleted = ApexPages.currentPage().getParameters().get('isJobCompleted');
    	}
    	public PageReference updateRec() {
    		
    		objectAPIName obj = new objectAPIName();
    		obj.Id = recId;
    		obj.fieldAPIName = isJobCompleted;
    		update obj;
    	}
    }
  • Then add created visualforce page in to site Visualforce Page (Setup | Develop | Sites | Default website | Site Visualforce Pages )
  • Create email template and add site link in email with parameters. refer following links​.
  •  
    http://mydomain.force.com/ updateJobStatus? recId =a1cN0000000Vr6R& isJobCompleted Yes
    http://mydomain.force.com/ updateJobStatus? recId =a1cN0000000Vr6R& isJobCompleted =No
     
     
    When user click on given link then visualforce page will open and record will update automatically.
     
    Regards,
    Yogesh More
    more.yogesh422@gmail.com || Skype:-yogesh.more44
This was selected as the best answer
Alex Von HasslerAlex Von Hassler
Yogesh, 

I added the visual force page, updated the apex class with the correct object name/field name and tested the email template, but when I click on the link to go to the VF page I get this:

User-added image

Any idea on how I could solve this? 

Thank you so much!
Alex
 
YogeshMoreYogeshMore
Make sure you have given object level permission to site user.
Go to (Setup | Develop | Sites) and click on public access setting.
Site should be active.
Add created page as an Active Site Home Page.
 
Alex Von HasslerAlex Von Hassler
Thank you so much for all your help so far. It took me a while to continue working on this project but this is what I have so far...
This setup is based on your posts and those of a previous topic. 

Custom Object: Customer_Issue__c
Custom Field: Status__c
(type picklist with options=: "Solved" and "Not Solved")

I have a workflow that sends out a HTMl email with the two links. The links are setup with the custom site and custom object ID. 
<a href="http://my-custom-domain.com/MyCustomVFPage?ObjectId=01Ig00000005UVv&ResponseCode=Solved">The issue has been solved.</a>  <p>
<a href="http://my-custom-domain.com/MyCustomVFPage?ObjectId=01Ig00000005UVv&ResponseCode=Not Solved">The issue has NOT been solved.</a>

Next is the visual force page:
<apex:page id="Page" showHeader="false" controller="MyCustomVFPage_CTR" action="{!updateRec}" cache="false">
    <apex:form >
        Thank you for your custom.
    </apex:form>
</apex:page>

Here is the 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 updateRec() {
        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;
        
       } return null;
   }
}

I don't get any errors and can get to the page when I click on the link in the email. I must be losing the connection somewhere along the line. The field just doesn't update. 

Any idea what could be wrong or missing? 

Thank you!

Alex


 
YogeshMoreYogeshMore
Alex,
  • Set debug log for site user and try to find error in logs after clicking on template link.
  • Make sure you have given object level permission to site user. Go to (Setup | Develop | Sites) and click on public access setting.
  • Add Page and Class in site user profile.


Regards,
Yogesh
more.yogesh422@gmail.com || Skype:-yogesh.more44
http://www.yogeshmore.com/ || +919096872010

 
Alex Von HasslerAlex Von Hassler
YogRaj, 

I've given object permissions to the user and added the site and class to the profile. 
I also added the Site Guest User to the Debug Logs, but it's not showing any logs for the user when I send the email and click on the link.The only logs I get are the ones from the workflow that sends the email. 

I have the feeling that there is a disconnect between the link in the email and the apex class. Any idea why, or what I could try next? 

Thank you,
Alex
 
Alex Von HasslerAlex Von Hassler
YogRaj, 

I figured it out! After I implemented your last suggestion I also had to change the Object ID in the link to the Record ID by using a merge field in the email template. Now it works perfectly!

I hope these posts will help someone else out there.  

Thank you SO much for your help YogRaj!

Alex
Shaik JeelanShaik Jeelan
Nice...post thank for info get best Whatsapp status video (https://statussove.com/whatsapp-status-video/) Watch and Download free
HaslettHaslett
Yes, you can. I think you should have to take a break and listen to your favorite song on Spotify Premium Apk (https://thinkkers.com/spotify-mod-apk/) which is the best music streaming platform available on the internet.
mahesh sharma 11mahesh sharma 11
If you are looking for the Latest One Spotify Premium Apk (https://spotifywire.com/spotify-premium-apk/) then you may go here and grab the opportunity to earn more and working features of premium for free. you can enjoy unlimited of music without having any ads.