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
prazonprazon 

Urgent help required: cannot save value of radio button in the object

Hi I have done the following code the value is not saving in the database. Please help me

 

<apex:outputText value="{!$ObjectType.Flag_Reporter__c.fields.Flag_for_Editorial__c.label}: " style="color:black;font-size:14px"/>
                    <apex:selectRadio value="{!editorial}" required="true">
                            <apex:actionSupport event="onchange" action="{!EditMethod}"/>
                            <apex:selectOptions value="{!items}"/>
                    </apex:selectRadio>
                </td>

 class is here

public String editorial{get;set;}

public void EditMethod(){
        flagReport[0].Flag_for_Editorial__c = this.editorial;
    }

public Pagereference save(){
        Boolean edited = false;
        if(flagReport[0].Flag_for_Editorial__c!= NULL){
           
            edited = true;
        }

 try{
            if(edited == true){
                update flagReport;
}

}

 

Best Answer chosen by Admin (Salesforce Developers) 
bob_buzzardbob_buzzard

You have immediate="true" on your commandbuttons - that discards any changes you have made and refreshes the page with the original values.  If you remove those it should start working.

All Answers

bob_buzzardbob_buzzard

Can you tell us the error that you are seeing?

prazonprazon

It is not saving the data I have set in the database, it is coming null

bob_buzzardbob_buzzard

Have you added debug to see if your EditMethod is being invoked?

prazonprazon

On selection it is getting refreshed..but whether I choose onselect or onchange this is not working...please help me which can save value to the database

bob_buzzardbob_buzzard

You may need to supply a rerender attribute for the onchange event - I've seen odd behaviour around that sort of thing in the past.

bob_buzzardbob_buzzard

Also, can you post some more of your code - for instance, how the flagReport list is created?

prazonprazon

Hi Bob,

 

I don't want to render any portion of the page but save the value selected in the database...please help me...

prazonprazon

Here it is

 

public Account_Flag_Status_Controller(ApexPages.StandardController controller) {
        mainAccount= (Account)controller.getRecord();
        AccountId = mainAccount.Id;
        flagReport = [Select Overall_Status__c, LeadQualityFlag__c, CreditCheckFlag__c,Venue__c, CompanyAgeFlag__c,Flag_for_Editorial__c, WebsiteFlag__c, Overall_Mystery_Shopping__c,Overall_PM_Assessment__c,Overall_Escalation__c, Flag_comments__c, Overall_comments__c  from Flag_Reporter__c Where Account_Flag__c=:AccountId LIMIT 1];
    }

 

bob_buzzardbob_buzzard

So rather than carrying out ajax requests, why don't you simply check the value when the save method is invoked - something like:

 

<apex:outputText value="{!$ObjectType.Flag_Reporter__c.fields.Flag_for_Editorial__c.label}: " style="color:black;font-size:14px"/>
<apex:selectRadio value="{!editorial}" required="true">
   <apex:selectOptions value="{!items}"/>
</apex:selectRadio>

 and in the controller, you can check the value of editorial, as it will be populated via the postback:

 

if (null!=editorial)
{
   update flagReport;
}

 

prazonprazon

This was the code earlier

 

where I put this in the save method

 

<apex:outputText value="{!$ObjectType.Flag_Reporter__c.fields.Flag_for_Editorial__c.label}: " style="color:black;font-size:14px"/>
                    <apex:selectRadio value="{!editorial}" required="true">                            
                            <apex:selectOptions value="{!items}"/>
                    </apex:selectRadio> 


public Pagereference save(){
        Boolean edited = false;
        if(this.editorial!= NULL){
           flagReport[0].Flag_for_Editorial__c = this.editorial;
            edited = true;
        }    
        
        if(this.website!= NULL){
           flagReport[0].WebsiteFlag__c = this.editorial;
            edited = true;
        }
        if(this.venue!= NULL){
            flagReport[0].Venue__c = this.editorial;
            edited = true;
        }
        
        
        try{
            if(edited == true){
                update flagReport;
            
                PageReference pgRef = new PageReference('/apex/flagStatusPage?id=' + AccountId); 
                pgRef.setRedirect(true);
                return pgRef;
            }
            else{
                return null;
            }
          
            
        }catch(Exception ex){
            ex.getMessage();
            
            return null;
        }

 

bob_buzzardbob_buzzard

I assume you posted this because you had an issue with that code?

prazonprazon

Yupe...this one was the original....please tell me where it gone wrong

bob_buzzardbob_buzzard

Have you checked the debug logs to confirm you aren't getting an exception - at the moment you are just swallowing it if one occurs.

prazonprazon

I am checking Flag_Reporter__c object..values are not chaning

prazonprazon

changing*

prazonprazon

Hi Bob,

 

checked it in debug, it is coming null as confirmed

bob_buzzardbob_buzzard

So you aren't getting an exception but the values aren't being posted back either?  That sounds very odd. Can you post the full page and controller?

prazonprazon

page:

 

<apex:page> 
<apex:form >
        <apex:pageBlock tabStyle="Account">
        <table width="100%">
        <tr><td width="100%" align="center">
        <apex:panelGrid columns="5" bgcolor="#343434" width="100%"  >
           
            
            <apex:outputPanel >
                <apex:image value="{!$Resource.logo_groupon}" height="40" />
                <apex:outputText value="Flag Reports" styleclass="toolbar"/>
            </apex:outputPanel>
            <apex:outputPanel >
                <apex:image value="{!$Resource.icon_account}" height="40" width="80"/>
                <apex:outputText value="{!Account.Name}" styleclass="toolbar"/>
            </apex:outputPanel>
            <apex:outputPanel >
                <apex:variable var="imageVar" value="{!colorSetter.overallStatus}"/> 
                <apex:image height="40" url="{!URLFOR($Resource.flags, imageVar)}"/>
                <apex:outputText value="Overall Status" styleclass="toolbar"/>
            </apex:outputPanel>
            <apex:commandLink action="{!back}" immediate="true">
                <apex:image value="{!$Resource.icon_close}" width="40" title="Back" style="float:right"/>
            </apex:commandLink>
            <apex:commandLink action="{!save}" immediate="true">
                <apex:image value="{!$Resource.icon_save}" width="40" title="Save" style="float:right"/>
            </apex:commandLink>
        </apex:panelGrid>
        </td></tr></table>
        </apex:pageBlock>
        <apex:pageBlock >
            <table>
            <tr>
                
                <td width="20%">
                <apex:outputText value="{!$ObjectType.Flag_Reporter__c.fields.Flag_for_Editorial__c.label}: " style="color:black;font-size:14px"/>
                    <apex:selectList value="{!editorial}" required="true" size="1">                            
                            <apex:selectOptions value="{!items}"/>
                    </apex:selectList>
                </td>
                <td width="20%">
                    <apex:outputText value="{!$ObjectType.Flag_Reporter__c.fields.WebsiteFlag__c.label}: " style="color:black;font-size:14px"/>
                    <apex:selectList value="{!website}" required="true"  size="1">                            
                            <apex:selectOptions value="{!items}"/>
                    </apex:selectList>
                </td>
                <td width="20%">
                    <apex:outputText value="{!$ObjectType.Flag_Reporter__c.fields.Venue__c.label}: " style="color:black;font-size:14px"/>
                    <apex:selectList value="{!venue}"  required="true"  size="1">                            
                            <apex:selectOptions value="{!items}"/>
                    </apex:selectList>                
                </td>
                <td width="20%">
                    <apex:outputText value="{!$ObjectType.Flag_Reporter__c.fields.Flag_comments__c.label}: " style="color:black;font-size:14px"/>
                    <apex:inputTextarea value="{!flagReport[0].Flag_comments__c}" />                            
                                
                </td>
                <td width="20%">
                    <apex:outputText value="{!$ObjectType.Flag_Reporter__c.fields.Overall_comments__c.label}: " style="color:black;font-size:14px"/>
                    <apex:inputTextarea value="{!flagReport[0].Overall_comments__c}" />                           
                                 
                </td>
                
            </tr>
            </table>
        </apex:pageBlock>
        </apex:form>
</apex:page>

 

 

public with sharing class Account_Flag_Status_Controller {
    
    public Id AccountId{get;set;}
    public Account mainAccount;
    public List<Flag_Reporter__c> flagReport{get;set;}
    public Account_Flag_Status_Controller(ApexPages.StandardController controller) {
        mainAccount= (Account)controller.getRecord();
        AccountId = mainAccount.Id;
        flagReport = [Select Overall_Status__c, LeadQualityFlag__c, CreditCheckFlag__c,Venue__c, CompanyAgeFlag__c,Flag_for_Editorial__c, WebsiteFlag__c, Overall_Mystery_Shopping__c,Overall_PM_Assessment__c,Overall_Escalation__c, Flag_comments__c, Overall_comments__c  from Flag_Reporter__c Where Account_Flag__c=:AccountId LIMIT 1];
    }
    
     public List<SelectOption> getItems() {
            List<SelectOption> options = new List<SelectOption>();
            options.add(new SelectOption('GREEN','GREEN'));
            options.add(new SelectOption('YELLOW','YELLOW'));
            options.add(new SelectOption('RED','RED'));
            
            return options;
     }
     
    public String editorial{get;set;}
    public String website{get;set;}
    
    public String venue{get;set;}  
   
    
    
    
    public Pagereference back() {
        Pagereference contractPage = new Pagereference('/' + AccountId);
        return contractPage;
    }
    
   
    
  
    
    public Pagereference save(){
        Boolean edited = false;
        System.debug(Logginglevel.DEBUG,'Editorial value: '+this.editorial);
        if(this.editorial!= NULL){
            
           flagReport[0].Flag_for_Editorial__c = this.editorial;
           edited = true;
        }    
        System.debug(Logginglevel.DEBUG,'Editorial value: '+this.website);
        if(this.website != NULL){
           
           flagReport[0].WebsiteFlag__c = this.editorial;
           edited = true;
        }
        System.debug(Logginglevel.DEBUG,'Editorial value: '+this.venue);
        if(flagReport[0].Venue__c!= NULL){
        
           flagReport[0].Venue__c = this.editorial;
           edited = true;
        }
        
        
        try{
            if(edited == true){
                update flagReport;
            
                PageReference pgRef = new PageReference('/apex/flagStatusPage?id=' + AccountId); 
                
                return null;
            }
            else{
                return null;
            }
          
            
        }catch(Exception ex){
            ex.getMessage();
            
            return null;
        }
    
    
    
    }
    

}

 

prazonprazon

header of the page

 

<apex:page standardStylesheets="false" standardController="Account" extensions="Account_Flag_Status_Controller">

bob_buzzardbob_buzzard

You have immediate="true" on your commandbuttons - that discards any changes you have made and refreshes the page with the original values.  If you remove those it should start working.

This was selected as the best answer
prazonprazon

tried javascript too....why this value is not carrying it on the class?

 

function setValues(f){
              
              if(document.getElementById('ediGreen').checked = true){
                  alert(document.getElementById('ediGreen').value);
                  document.getElementById('edi').value = 'GREEN';
                  alert(document.getElementById('edi').value);
              }if(document.getElementById('ediYellow').checked = true){
                  document.getElementById('edi').value = 'YELLOW';
              }if(document.getElementById('ediRed').checked = true){
                  document.getElementById('edi').value = 'RED';
              }    
             
                  
              if(document.getElementById('webGreen').checked = true){
                  document.getElementById('web').value = 'GREEN';
              }if(document.getElementById('webYellow').checked = true){
                  document.getElementById('web').value = 'YELLOW';
              }if(document.getElementById('webRed').checked = true){
                  document.getElementById('web').value = 'RED';
              }
                  
              if(document.getElementById('venGreen').checked = true){
                  document.getElementById('ven').value = 'GREEN';
              }if(document.getElementById('venYellow').checked = true){
                  document.getElementById('ven').value = 'YELLOW';
              }if(document.getElementById('venRed').checked = true){
                  document.getElementById('ven').value = 'RED';
              }
       }

<td width="20%">
                <apex:outputText value="{!$ObjectType.Flag_Reporter__c.fields.Flag_for_Editorial__c.label}: " style="color:black;font-size:14px"/>
                    <input id="edi" name="edi" type="hidden" value="{!editorial}"/>
                    <input id="ediGreen" name="ediGreen" type="radio"  value="GREEN" onclick="setValues(this)">GREEN</input>
                    <input id="webYellow" name="ediGreen" type="radio"  value="YELLOW" onclick="setValues(this)"> YELLOW</input>
                    <input id="webRed" name="ediGreen" type="radio" value="RED" onclick="setValues(this)">RED</input>
                </td>
                <td width="20%">
                    <apex:outputText value="{!$ObjectType.Flag_Reporter__c.fields.WebsiteFlag__c.label}: " style="color:black;font-size:14px"/>
                    <input id="web" name="web" type="hidden" value="{!website}" onclick="setValues(this)"/>
                    <input id="webGreen" name="webGreen" type="radio"  value="GREEN" onclick="setValues(this)">GREEN</input>
                    <input id="webYellow" name="webGreen" type="radio"  value="YELLOW" onclick="setValues(this)"> YELLOW</input>
                    <input id="webRed" name="webGreen" type="radio" value="RED">RED</input>
                </td>
                <td width="20%">
                    <apex:outputText value="{!$ObjectType.Flag_Reporter__c.fields.Venue__c.label}: " style="color:black;font-size:14px"/>
                    <input id="ven" name="ven" type="hidden" value="{!venue}"/>
                    <input id="venGreen" name="venGreen" type="radio"  value="GREEN" onclick="setValues(this)">GREEN</input>
                    <input id="venYellow" name="venGreen" type="radio"  value="YELLOW" onclick="setValues(this)"> YELLOW</input>
                    <input id="venRed" name="venGreen" type="radio" value="RED" onclick="setValues(this)">RED</input>               
                </td>

 

prazonprazon

Removed immediate=true, but still it is not working :(

bob_buzzardbob_buzzard

I can't really work out what the page is doing now.  You should not require javascript for this - by setting the value of the input component to a controller property, that will be filled in by the postback.

prazonprazon

It worked ultimately..thanks Bob :) ....take a bow

bob_buzzardbob_buzzard

Glad to hear it.