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
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.
alex hales 18alex hales 18
If you are looking for the app providing plateform the BlackMart APK (https://modapky.com/blackmart-apk/) is the perfect palteform.
Walker KaleWalker Kale
Yes, you can. but be aware of fraudulent mail and stay secure from an online phishing attacks.
Sims FreeplaySims Freeplay
I hope these posts will help someone else out there.  
The Sims Freeplay Mod Apk (https://f5zones.com/the-sims-freeplay-mod-apk/)
Harshitha KPHarshitha KP
Hi Yogesh,

i tried this whole setup in my developer org and it is working fine. But whem i try cretaing the same on my Sandbox i am getting the below error for Apex class. Please help asap

Error: Compile Error: Variable does not exist: Id at line 15 column 13

public class updateDownloadedStatus{

    public String recId {get;set;}
    public String isJobCompleted {get;set;}

    public updateDownloadedStatus() 
    {
        recId = ApexPages.currentPage().getParameters().get('recId');
        //isJobCompleted = ApexPages.currentPage().getParameters().get('isDownloadCompleted');
    }
    public PageReference updateRec() 
    {
        
        Contact obj = new Contact();
        obj.Id = recId;
        obj.testM__IsDownloaded__c =true;
        update obj;
      
        return null;
    }
}


Thanks in advance
Harshitha
tricks dbtricks db
download mod apk free  (https://tricksdb.com/)
robert lan 4robert lan 4
Download Vidmate Apk (https://techlarapoint.com/vidmate-apk/) as well. 
thelad Modsthelad Mods
I'm not that good with programming, but StackOverflow is where you can find answers to your question. Download Spotify Premium Apk (https://theladmods.com/blog/get-spotify-premium-for-free/)
Bella bellBella bell
Download and install mod games ad app. Get all your  favourite choice in one place (https://mymoddedapk.com/)
Bella bellBella bell
Install and download all types of mod games (https://topmoddedapk.com/)
Also, get on (https://emiratesapk.com/)
kalli jonerkalli joner
es, you can. I think you should have to take a break and listen to your favorite Cooking Fever Mod Apk (https://apkylo.com/cooking-fever-mod-apk/) which is the best music streaming platform available on the internet. Free Fire Mod APK (https://trickmekar.com/garena-free-fire-mod-apk/)
Saleem MaharSaleem Mahar
Alex Won Hasier, the email body you have set to send contains id = 'id', like you must ensure = sign after in the url.
Jakartia KalenaJakartia Kalena
Once I implemented your concluding suggestion, I observed that I needed to make modifications in the Object ID to the Record ID in the link as indicated via email template Like (https://queenapk.com/old-roll-mod-apk/). It now works as intended!
Abu HadiAbu Hadi

If you are looking for some online Quran learning apps I'm gonna share them with you

Online Quran Classes (https://www.onlinequranclasses.com/)

Learn Quran Online (https://www.myqurantutor.com/)

Mohamed AhshanMohamed Ahshan
Is it possible to do without code?
Srbija OglasiSrbija Oglasi
I implemented the given code but it looks like I didn't do something right on the site (https://seo11.pro/) so I crashed it and had to re-upload it as everything was lost all of a sudden.
Kartia JalenKartia Jalen
Once I executed your concluding recommendation, I observed that I needed to modify the Object ID to the Record ID in the link indicated via email template (https://apkpuro.com/old-roll-mod-apk/). It now works as intended!
ApkMafia ModApkMafia Mod
As I followed your final piece of advice, I discovered that the Object ID in the link provided by the email template needed to be changed to the Record ID. (https://apkmafiamod.com/)
Jameka KalandoJameka Kalando
After putting your final recommendation into practice, I noticed that I had to make some changes to the Object ID and update it to the Record ID in the link, as per the instructions provided in the email template, such as in the example of (https://apkkingo.com/manga-dogs-premium-apk/). With these modifications, the link now functions as intended.
Hari BhaiHari Bhai
Download DID studio mod apk frm here https://ourmobileapps.com/d-id-studio-mod-apk/ and enjoy unlimited free redits and remove watermark.
Amelia JamesAmelia James

Once I followed your suggestions, I observed that I will have to make changes in the Object ID to the Record ID in the link as indicated via email template Like (https://oldrollmodapk.com/). It now works fine!
Hari BhaiHari Bhai
Prepare for continuous 3D action in Autogun Heroes MOD APK (https://topsinblue.com/autogun-heroes-mod-apk/). You'll be leading a team of heroes on a mission to reclaim control of a world overrun by aliens! Also download - https://topsinblue.com/frozen-city-mod-apk/