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
ArrgHunterArrgHunter 

custom field not getting updated

Hi,

 

i have created custom controller and want to update a custom field with value based on the button user clicked on the vf page.

 

somehow my field is not being updated. any help will be appreciated as i have spent lot of time on it but unable to fix it.

it will be big help for a charity.

public class IRPTemplateSelection {


public IRPTemplateSelection(){
}

public PageReference TemplateSelection() {
        
System.currentPageReference().getParameters().get('Templateid');
       try {
      	
    		Orphan__c MyOrp = new Orphan__c();
 			String TemplateId = Apexpages.currentPage().getParameters().get('Templateid');
        	
        	if (TemplateId != '')
        		{myorp.Biodata_Report_Template_4_Conductor__c = TemplateId;}
        	else
        		{myorp.Biodata_Report_Template_4_Conductor__c = 'a0JP0000001qGwU';}
        update (myorp);
       } catch(System.DMLException e) {
           ApexPages.addMessages(e);
           return null;
    }
    	        PageReference pageRef = new PageReference('https://cs4.salesforce.com/a0A?fcf=00B20000005raAO');
    	    pageRef.setRedirect(false);

        return pageRef; 
    
}
}
<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" action="{!TemplateSelection}" />
            <apex:param name="Templateid" value="a0JP0000001qGwU" />            
        </apex:pageBlockButtons>
        <apex:pageBlockButtons >
            <apex:commandButton title="Select BioData Template" value="Arabic BioData Template" action="{!TemplateSelection}"/>
            <apex:param name="Templateid" value="a0JP0000001q86Q" />
        </apex:pageBlockButtons>
                    <apex:facet name="header">Choose Template</apex:facet>
                    <apex:outputText value="template">
                        <apex:param value="test template" />
                    </apex:outputText>
      </apex:pageBlock>
     <apex:pageBlock title="Simple Title">
   <b>Hello <i>{!$User.FirstName} {!$User.Country}</i></b>
   { if {!$User.Country} }
 </apex:pageBlock>
     </apex:outputPanel>
     </apex:form>

<!-- End Default Content REMOVE THIS -->
</apex:page>

 

 

code is as below.

 

thanks

Ankit AroraAnkit Arora

Code is highlighted in red, enjoy :)

 

VFP :

 

<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 reRender="resultsBlock" title="Select BioData Template" value="English BioData Template" action="{!TemplateSelection}"> <apex:param assignTo="{!TempId}" name="Templateid" value="a0JP0000001qGwU" /> </apex:commandButton>
        </apex:pageBlockButtons>
        <apex:pageBlockButtons >
            <apex:commandButton title="Select BioData Template" value="Arabic BioData Template" action="{!TemplateSelection}"> <apex:param assignTo="{!TempId}" name="Templateid" value="a0JP0000001q86Q" /> </apex:commandButton>
        </apex:pageBlockButtons>
                    <apex:facet name="header">Choose Template</apex:facet>
                    <apex:outputText value="template">
                        <apex:param value="test template" />
                    </apex:outputText>
      </apex:pageBlock>
     <apex:pageBlock title="Simple Title">
   <b>Hello <i>{!$User.FirstName} {!$User.Country}</i></b>
   { if {!$User.Country} }
 </apex:pageBlock>
     </apex:outputPanel>
     </apex:form>

<!-- End Default Content REMOVE THIS -->
</apex:page>

 

Apex :

 

public class IRPTemplateSelection {


public String TempId {get; set;}

public IRPTemplateSelection(){
    TempId = 'test' ;
}

public PageReference TemplateSelection() {
System.debug('TempId :::: ' + TempId) ;        
System.currentPageReference().getParameters().get('Templateid');
       try {
        
            Account MyOrp = new Account();
            String TemplateId = Apexpages.currentPage().getParameters().get('Templateid');
            
            if (TemplateId != '')
                {myorp.Name = TemplateId;}
            else
                {myorp.Name = 'a0JP0000001qGwU';}
        update (myorp);
       } catch(System.DMLException e) {
           ApexPages.addMessages(e);
           return null;
    }
                PageReference pageRef = new PageReference('https://cs4.salesforce.com/a0A?fcf=00B20000005raAO');
            pageRef.setRedirect(false);

        return pageRef; 
    
}
}

 

Thanks

Ankit Arora

Blog | Facebook | Blog Page