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

Updating custom field in visualforce page


I have built a visualforce page with custom controller. On my vf page I have 3 buttons. I want to update a custom field when a user clicks on one of the buttons and then want to redirect the user to different page.

Any idea what is the best way to achieve this.



//My custom controller class

public class IRPTemplateSelection {

 public PageReference TemplateSelection() {

String TemplateId = ApexPages.currentPage().getParameters().get('Templateid');

if (TemplateId == 'a0JP0000001qGwU') 
			{Orphan__c.Biodata_Report_Template__c = 'a0JP0000001qGwU';} 
else if (TemplateId == 'a0JP0000001q86Q')
			{Orphan__c.Biodata_Report_Template__c = 'a0JP0000001q86Q';}
			{Orphan__c.Biodata_Report_Template__c = 'a0JP0000001q86Q';}

	      PageReference pageRef = new PageReference('' );

	    return pageRef; 

VF Page

<apex:page controller="IRPTemplateSelection" title="Template Selection" id="Templateselectionpage">
<!-- Begin Default Content REMOVE THIS -->
<h1>Biodata Template Selection</h1>

    <apex:form id="allocOrphansForm" >
    <apex:outputPanel >
       <apex:pageBlock id="resultsBlock">
        <apex:pageBlockButtons >
            <apex:commandButton title="Select BioData Template" value="English BioData Template" />
            <apex:param name="Templateid" value="a0JP0000001qGwU" />            
        <apex:pageBlockButtons >
            <apex:commandButton title="Select BioData Template" value="Arabic BioData Template" />
            <apex:param name="Templateid2" value="a0JP0000001q86Q" />
                    <apex:facet name="header">Choose Template</apex:facet>
                    <apex:outputText value="template">
                        <apex:param value="test template" />

     <apex:pageBlock title="Simple Title">
   <b>Hello <i>{!$User.FirstName}</i>.</b>

<!-- End Default Content REMOVE THIS -->

Baktash H.Baktash H.

One way would be:

Every button calls another function which redirects the user to a different page.

If you want to use only one function try to use apex:params to tell the  controller which button was pressed.



the redirection will be to the same one page. i want to update the custom field and then redirect the users to oppertunities page.


am i  missing anything from the code above.


note: i have changed redirection URL





i though it will be very simple thing.

am i missing anything? experts...