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
Sami ShakithSami Shakith 

Onchange function is not working properly for formula field

Hi,

I am trying to create a VF page for filteration .In that i have 3 filteration. Here is my code.
<apex:page standardcontroller="Opportunity" extensions="QuoteControll2" sidebar="false" > 
  <apex:form > 
  
  <apex:pageBlock > 
  <html>
  <body>
  <table>
  <tr>
  <apex:pageBlockSection > 
  
  <td><table border="0" bgcolor="#00BFFF" >
      <tr><apex:inputField value="{!SearchCriteria.Operating_Model__c}"/></tr>
      <tr><apex:inputText label="Quantity" value="{!Quantity}" style="width : 90%"/> </tr>
      
  <tr><apex:commandButton value="Go" action="{!filterApplicant}" /> </tr>
  </table>
  </td>
  
    </apex:pageBlockSection>   
   
       <apex:pageBlockSection >
       <apex:inputField label="Region" value="{!SearchCriteria.Region__c}" rendered="{!region}">
            <apex:actionsupport event="onchange" action="{!filterapp}" />   
          </apex:inputField>     
       
         <tr><apex:inputField value="{!SearchCriteria.partno__r.type__c}" id="degreeLevel" onchange="assignDegreeLevel(this.value)" rendered="{!typef}">      
               <apex:actionSupport event="onchange" action="{!filterapp}"/>
        </apex:inputField></tr>
 <apex:actionFunction name="assignDegreeLevel" action="{!filterapp}" 
   reRender="program" immediate="true">
      <apex:param name="degreeSelected" assignTo="{!degreeSelected}" value=""/>
 </apex:actionFunction>
 </apex:pageBlockSection>
       

      <td style="width:100%"><apex:pageBlockTable value="{!FilteredApplicants}" var="applicant" > 
          <apex:column >
            <apex:inputCheckbox value="{!selected}"/>      
          </apex:column>
          <apex:column value="{!applicant.Operating_Model__c}" />
          <apex:column value="{!applicant.MSRP__c}"/>
          <apex:column value="{!applicant.Buying_Price__c}"/> 
          <apex:column value="{!applicant.Type__c}"/>
      </apex:pageBlockTable>
      <apex:pageMessages id="error"></apex:pageMessages>
     
      </td></tr>
      </table>
      </body>
      </html>
  </apex:pageBlock> 
   </apex:form> 
</apex:page>

At 1st it consider the operating model and quantity after clicking go button that page will list the record which met the criteria. Then i have 2 picklist for filtration one Region and another is Type. For the both filteration i gave onchange action. Region is working properly but Type onchange function is not working.

Type field is formula field which takes value from another object. Please i need someone help. I am new to salesforce.
Best Answer chosen by Sami Shakith
ericmonteericmonte
<apex:page standardcontroller="Opportunity" extensions="QuoteControll2" sidebar="false" > 
    <apex:form > 
        <apex:pageBlock>
            <apex:pageBlockSection > 
                
                <td><table border="0" bgcolor="#00BFFF" >
                    <tr><apex:inputField value="{!SearchCriteria.Operating_Model__c}"/></tr>
                    <tr><apex:inputText label="Quantity" value="{!Quantity}" style="width : 90%"/> </tr>
                    
                    <tr><apex:commandButton value="Go" action="{!filterApplicant}" /> </tr>
                    </table>
                </td>
                
            </apex:pageBlockSection>   
            
            <apex:pageBlockSection >
                <apex:inputField label="Region" value="{!SearchCriteria.Region__c}" rendered="{!region}">
                    <apex:actionsupport event="onchange" action="{!filterapp}" />   
                </apex:inputField>     
                
                <tr><apex:inputField value="{!SearchCriteria.partno__r.type__c}" id="degreeLevel" onchange="assignDegreeLevel(this.value)" rendered="{!typef}">      
                    <apex:actionSupport event="onchange" action="{!filterapp}" reRender="reRenderPbId"/>
                    </apex:inputField></tr>
                <apex:actionFunction name="assignDegreeLevel" action="{!filterapp}" 
                                     reRender="reRenderPbId" immediate="true">
                    <apex:param name="degreeSelected" assignTo="{!degreeSelected}" value=""/>
                </apex:actionFunction>
            </apex:pageBlockSection>
            
            
            <td style="width:100%">
                
                <apex:pageBlockTable value="{!FilteredApplicants}" var="applicant" id="reRenderPbId" > 
                <apex:column >
                    <apex:inputCheckbox value="{!selected}"/>      
                </apex:column>
                <apex:column value="{!applicant.Operating_Model__c}" />
                <apex:column value="{!applicant.MSRP__c}"/>
                <apex:column value="{!applicant.Buying_Price__c}"/> 
                <apex:column value="{!applicant.Type__c}"/>
                </apex:pageBlockTable>
                <apex:pageMessages id="error"></apex:pageMessages>
                
            </td>    
        </apex:pageBlock>
    </apex:form> 
</apex:page>
Refactored the code look at the changes I made. Does that make sense? I'm assuming you are trying to reRender the PageBlock Table after you you do an action function. You had a ReRender, but you didn't point it to a specific block or element you are trying to refresh.

All Answers

ericmonteericmonte
Please post your extension code. 
Nitin SehgalNitin Sehgal
Hi Sami Shahul,

I have seen your code and will suggest you to use a actionFunction only for Type field because as I can see in your code, you are trying to call to methods on the same event (i.e. onchange) one is action function and another is action support and both are calling the same controller method.

Try to remove one of them and it will work.
Sami ShakithSami Shakith
Hi ericmonte,

    Thanks for your replay. Bellow is my code
public with sharing class QuoteController{ 
public String degreeSelected{get;set;}
public Integer Quantity{get;set;}
public Boolean selected{get;set;}
public Boolean gobttn{get;set;}
public Boolean region{get;set;}
public Boolean typef{get;set;}
public boolean check{get;set;}
public boolean godisable{get;set;}
public String reg{get;set;}
public List<Parts__c> types{get;set;}   
public List<Price_details__c> FilteredApplicants{get;set;}  
public Price_details__c SearchCriteria{get;set;} 

   public QuoteController(ApexPages.StandardController controller)  { 
   SearchCriteria = new Price_details__c(); 
   types = new list<Parts__c>();
   types=[select type__c from parts__c];
   selected = false;
  // gobttn = false;
   region = false;
   typef= false;
   check =false; 
   }
    
     public void filterApplicant() { 
   region = true;
   typef = true;
   check= true;
 //gobttn =true;
 
 FilteredApplicants = new List<Price_details__c>(); 
         if(SearchCriteria.Operating_Model__c!=null && Quantity!=null && degreeSelected==null && SearchCriteria.Region__c==null)
 {
        FilteredApplicants = [SELECT Id, Name, Region__c, MSRP__c, Operating_Model__c, Buying_Price__c, QuantityStart__c,QuantityEnd__c,Type__c 
        FROM Price_details__c WHERE Operating_Model__c =: SearchCriteria.Operating_Model__c and QuantityStart__c<=:Quantity 
        and QuantityEnd__c>=:Quantity];
        system.debug('method1');
     
   if(FilteredApplicants.size() == 0) 
      { 
      Apexpages.addMessage(new ApexPages.Message

(ApexPages.Severity.INFO,''+'No records to Display'));  
     }}
    
     
    
 }
     
     
     
     public void filterapp(){
     
      FilteredApplicants = new List<Price_details__c>(); 
      
      
      if(SearchCriteria.Operating_Model__c!=null && Quantity!=null && SearchCriteria.Region__c!=null && degreeSelected==null){
   
   FilteredApplicants = [SELECT Id, Name, Region__c, MSRP__c, Operating_Model__c, Buying_Price__c, QuantityStart__c,QuantityEnd__c,Type__c 
        FROM Price_details__c WHERE Operating_Model__c =: SearchCriteria.Operating_Model__c and QuantityStart__c<=:Quantity 
        and QuantityEnd__c>=:Quantity and region__c=:SearchCriteria.region__c ];
        system.debug('Entered inside');
     
   if(FilteredApplicants.size() == 0) 
      { 
      Apexpages.addMessage(new ApexPages.Message

(ApexPages.Severity.INFO,''+'No records to Display for the  region'));  
     }
     
   } else if(SearchCriteria.Operating_Model__c!=null && Quantity!=null && degreeSelected!=null && SearchCriteria.Region__c==null){
   
   FilteredApplicants = [SELECT Id, Name, Region__c, MSRP__c, Operating_Model__c, Buying_Price__c, QuantityStart__c,QuantityEnd__c,Type__c 
        FROM Price_details__c WHERE Operating_Model__c =: SearchCriteria.Operating_Model__c and QuantityStart__c<=:Quantity 
        and QuantityEnd__c>=:Quantity and Type__c=:degreeSelected];
        system.debug('Entered inside');
     
   if(FilteredApplicants.size() == 0) 
      { 
      Apexpages.addMessage(new ApexPages.Message

(ApexPages.Severity.INFO,''+'No records to Display for the type '));  
     }
     
   } else if(SearchCriteria.Operating_Model__c!=null && Quantity!=null && SearchCriteria.Region__c!=null && degreeSelected!=null){
   
   FilteredApplicants = [SELECT Id, Name, Region__c, MSRP__c, Operating_Model__c, Buying_Price__c, QuantityStart__c,QuantityEnd__c,Type__c 
        FROM Price_details__c WHERE Operating_Model__c =: SearchCriteria.Operating_Model__c and QuantityStart__c<=:Quantity 
        and QuantityEnd__c>=:Quantity and region__c=:SearchCriteria.region__c and Type__c=:degreeSelected];
        system.debug('Entered inside');
     
   if(FilteredApplicants.size() == 0) 
      { 
      Apexpages.addMessage(new ApexPages.Message

(ApexPages.Severity.INFO,''+'No records to Display for the type and region'));  
     }
     
   }     
     
   
     
     
    
 }
     
     
}

Can you please suggest me.
Sami ShakithSami Shakith
Hi Nitin,

Thanks for your replay. As you told I removed actionSupport tag and tried then also type field is not working. Can you please give me suggestion.
Nitin SehgalNitin Sehgal
Did, you checked the debug Logs? May be it is calling the controller method and not refreashing the page because you are rerendering the control which has 'program' as an Id but as i can see in your page there is no control with that ID.

Check the javascript error by inspecting the page elements. Let me know if still there is any problem.
Sami ShakithSami Shakith
Thank you for your reply. I removed  that rerendered then that type field is refreshing, But it is not entered into that type condition. If i give region then it is entering in to the region condition. This thing I checked in debuglogs. Can you please give me your suggestion.
ericmonteericmonte

okay in your actionsupport and action function you are missing reRender. When an ActionSupport occurs, you need to rerender a particular item in the page.
 
<apex:actionsupport event="onchange" action="{!filterapp}" RERENDER="idoftheelement"/>


Also in your actionFunction you have a reRender
<apex:actionFunction name="assignDegreeLevel" action="{!filterapp}"  reRender="program" immediate="true">

But I don't see any data elements with id called "program".

 
ericmonteericmonte
Also here is a working exampl in one of my codes:
<tr>
                    
                    <td><apex:selectList size="1" value="{!regionValue}" id="regionList">
                        <apex:actionSupport event="onchange" reRender="contList"/>
                        <apex:selectOptions value="{!regions}"></apex:selectOptions>
                        </apex:selectList>
                    </td>		
                </tr>
                <tr>
                    
                    <td><apex:selectList size="1" value="{!countryValue}" id="contList">
                        <apex:actionSupport event="onchange" reRender="trials"/>
                        <apex:selectOptions value="{!countries}"></apex:selectOptions>
                        </apex:selectList>
                    </td>		
                </tr>
                <tr>
                    
                    <td><apex:selectList size="1" id="trials" value="{!trialId}">
                        <apex:actionSupport event="onchange" reRender="tSites"/>
                        <apex:selectOptions value="{!trials}"></apex:selectOptions>
                        </apex:selectList>
                    </td>
as you can see in my action support, I always tie it in with a ReRender that allows a refresh of your elements based on your controller and etc...
Sami ShakithSami Shakith
  Hello ericmonte,
I gave rerender as you told and I removed program, then it is refreshing the page if I give type field. But it is not working.
ericmonteericmonte
<apex:page standardcontroller="Opportunity" extensions="QuoteControll2" sidebar="false" > 
    <apex:form > 
        <apex:pageBlock>
            <apex:pageBlockSection > 
                
                <td><table border="0" bgcolor="#00BFFF" >
                    <tr><apex:inputField value="{!SearchCriteria.Operating_Model__c}"/></tr>
                    <tr><apex:inputText label="Quantity" value="{!Quantity}" style="width : 90%"/> </tr>
                    
                    <tr><apex:commandButton value="Go" action="{!filterApplicant}" /> </tr>
                    </table>
                </td>
                
            </apex:pageBlockSection>   
            
            <apex:pageBlockSection >
                <apex:inputField label="Region" value="{!SearchCriteria.Region__c}" rendered="{!region}">
                    <apex:actionsupport event="onchange" action="{!filterapp}" />   
                </apex:inputField>     
                
                <tr><apex:inputField value="{!SearchCriteria.partno__r.type__c}" id="degreeLevel" onchange="assignDegreeLevel(this.value)" rendered="{!typef}">      
                    <apex:actionSupport event="onchange" action="{!filterapp}" reRender="reRenderPbId"/>
                    </apex:inputField></tr>
                <apex:actionFunction name="assignDegreeLevel" action="{!filterapp}" 
                                     reRender="reRenderPbId" immediate="true">
                    <apex:param name="degreeSelected" assignTo="{!degreeSelected}" value=""/>
                </apex:actionFunction>
            </apex:pageBlockSection>
            
            
            <td style="width:100%">
                
                <apex:pageBlockTable value="{!FilteredApplicants}" var="applicant" id="reRenderPbId" > 
                <apex:column >
                    <apex:inputCheckbox value="{!selected}"/>      
                </apex:column>
                <apex:column value="{!applicant.Operating_Model__c}" />
                <apex:column value="{!applicant.MSRP__c}"/>
                <apex:column value="{!applicant.Buying_Price__c}"/> 
                <apex:column value="{!applicant.Type__c}"/>
                </apex:pageBlockTable>
                <apex:pageMessages id="error"></apex:pageMessages>
                
            </td>    
        </apex:pageBlock>
    </apex:form> 
</apex:page>
Refactored the code look at the changes I made. Does that make sense? I'm assuming you are trying to reRender the PageBlock Table after you you do an action function. You had a ReRender, but you didn't point it to a specific block or element you are trying to refresh.
This was selected as the best answer
Sami ShakithSami Shakith
Hi ericmonte,

Thank you for your suggestion. Now it is working properly.