Ask a Question
Ask Question Login
Corporate Training
  1. Community
  2. Salesforce
  3. Question
Salesforce

How to Update Field On Click of OutputLink in Visualforce

Asked by Michael Vaughan Aug 8, 2021 1.6K views 1 answer
Share

About this question

I have a link referencing one contact record in Visualforce page. On click of the said link, a number field from Contact object must be equal to 1. But field is blank each time I click the link. Meanwhile, here are the apex class and the visualforce page:

Apex Class:

public with sharing class OutputLinkController { private ApexPages.StandardController controller {get; set;} private Contact contact {get;set;} public Integer viewCount {get; set;} public OutputLinkController(ApexPages.StandardController controller) { this.controller = controller; this.contact = (Contact)controller.getRecord(); } public void processLinkClick() { viewCount = 1; } }

Visualforce Page:

   Contact record    

Modified Apex Class:

public with sharing class OutputLinkController { public Contact contact { public get; private set; } public OutputLinkController(ApexPages.StandardController controller) { this.contact = (Contact)controller.getRecord(); } public PageReference UpdateClickCount() { UpdateContact(contact.Id); return new PageReference('https://ap7.salesforce.com/?id=0032800000R4Cz3AAF'); } @future public static void UpdateContact(Id contactId) { Contact c = [SELECT Id, Record_View_Count__c FROM Contact WHERE Id = '0032800000R4Cz3AAF']; c.Record_View_Count__c = 1; update c; } }

Modified Visualforce Page:

   John Doe  

How to update apex:outputlink in visualforce?

Your answer

1 Answer

More Salesforce discussions

Learn & Explore

Free tutorials and interview questions from industry experts — learn the skill, then get ready to prove it.

Latest Salesforce Blogs

Guides, tips and career advice on Salesforce from JanBask experts.