0

I have one picklist field that contains hot, warm, cold. And I have one checkbox field.

If I choose Hot value in picklist field and checked the checkbox then picklist value should changed to cold.

<apex:page standardController="Account" extensions="accAcx" >
    <apex:form >
       <apex:pageblock >
          <apex:pageblocksection >
              <apex:inputfield value="{!Account.Name}" />
              <apex:outputpanel id="temperaturePickList">
                <apex:inputfield value="{!Account.Status__c}" />
              </apex:outputpanel>              
              <apex:inputfield value="{!Account.Self_Relation__c}">
                 <apex:actionSupport event="onchange" action="{!changePickList}" rerender="temperaturePickList" />
              </apex:inputfield>
          </apex:pageblocksection>          
       </apex:pageblock>
    </apex:form>
</apex:page>

public class accAcx {
    Public ApexPages.StandardController scontroller;
    Public Account accounts{get;set;}

    public accAcx(ApexPages.StandardController controller) {
      this.scontroller = controller;
      accounts=(Account) controller.getRecord();      
    }
    public Pagereference changePickList(){
     List<Account> acclst = [select Name, Status__c, Self_Relation__c from Account Where Id=: accounts.id]; 
     for(Account acc : acclst){
      if(acc.Self_Relation__c == true){
        acc.status__c='Delivered';
      }
     }
    } 

}
  • Use before insert trigger; if(picklist == 'Hot' && checkbox){ picklist = 'cold'; }; – itzmukeshy7 Apr 22 '16 at 6:45
  • @itzmukeshy7 - Am mentioned in visualforce page – user30910 Apr 22 '16 at 6:56
  • is account.status__c one of hot/warm/cold? and what does delivered have to do with this? Your problem statement is inconsistent – cropredy Apr 23 '16 at 6:16
1

When you use the default binding variable provided by the Standard controller(here Account), you cannot do any modifications to that binding variable and its fields in your extension controller.

So i would suggest you to use a variable (like accounts in your extension) from your extension controller to get the inputs.

<apex:page standardController="Account" extensions="accAcx" >
    <apex:form >
       <apex:pageblock >
          <apex:pageblocksection >
              <apex:inputfield value="{!accounts.Name}" />
              <apex:outputpanel id="temperaturePickList"><apex:inputfield value="{!accounts.Status__c}" /></apex:outputpanel>              
              <apex:inputfield value="{!accounts.Self_Relation__c}">
                 <apex:actionSupport event="onchange" action="{!changePickList}" rerender="temperaturePickList" />
              </apex:inputfield>
          </apex:pageblocksection>          
       </apex:pageblock>
    </apex:form>
</apex:page>

public class accAcx {
    Public Account accounts {get;set;}

    public accAcx(ApexPages.StandardController controller) {
      accounts=(Account) controller.getRecord();      
    }

    public void changePickList(){
        if(accounts.Status__c == 'Hot' && accounts.Self_Relation__c){
            accounts.Status__c == 'Cold';
        }
    } 
}

Hope it helps.

0

I would say, use an apex:actionSupport tag with the rerender attribute set to refresh the picklist

<apex:actionSupport event="onchange" action="{!changePickList}" rerender="temperaturePickList" />

and then in your controller define the

public PageReference changePickList(){
     if(myChebox== true) 
         temperaturePickList = 'cold';
}
  • Non void method must return value. If I return null it is not rendering. I updated with code – user30910 Apr 22 '16 at 7:10
  • 1
    return null, should refresh your page, but I have a question for you, do you really need to read the account from the DB? Is the checkBox in the page? – Vincenzo Denti Apr 22 '16 at 7:30
  • Yeah checkbox in page. – user30910 Apr 22 '16 at 8:01
  • 1
    So, you are coming from a onChange, the accounts variable that you are getting from the controller have the values from the page, set the values you need and return, saving the time of the db access. Then in the save ( the trigger or the validation rules ) would be checked if the values are consistent. just try with a void method, instead of return a PageReference. – Vincenzo Denti Apr 22 '16 at 8:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.