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
Sapana WSapana W 

Calculate values on the fly using actionSupport

Hi All,

Have already coded this thing. But its not working and am not not getting what the issue is.
Heres my code:


<apex:page standardController="Opportunity" extensions="OppAutoPopulateCTRL"  id="page">
   
    <apex:form id="myForm" >
       
        <apex:pageBlock mode="edit" >
           
            <apex:pageblocksection title="LMS Lookup" id="Contractsec1">
              
            <apex:pageblocksectionItem > 
              <apex:inputfield value="{!Opp.AccountId}" >
                 <apex:actionSupport event="onchange" action="{!autoPopulate}" reRender="panelConType"/>
               </apex:inputfield>     
          </apex:pageBlockSectionItem>
      
</apex:pageblocksection>
</apex:pageBlock>
<apex:pageBlock title="Popup">     
      <apex:pageblocksection >
<!--   Added to auto populate   -->
          <apex:pageblocksectionItem id="popup1" >        
             <apex:outputLabel value="{!$ObjectType.Opportunity.fields.MainCompetitors__c.label}" />
                 <apex:outputPanel id="panelConType" >
                     <apex:inputfield value="{!Opportunity.MainCompetitors__c}" />
                 </apex:outputPanel>
                 </apex:pageblocksectionItem>                
                <apex:inputfield value="{!Opportunity.CloseDate}" />
                <apex:inputfield value="{!Opportunity.StageName}" />
                <apex:inputfield value="{!Opportunity.Name}" />
                </apex:pageblocksection> 
    <apex:pageblockbuttons >
                    <apex:commandButton action="{!save}" value="Save" id="theButton"/>
      </apex:pageblockbuttons>
</apex:pageBlock>
  </apex:form>
</apex:page>






public class OppAutoPopulateCTRL {

    public Opportunity opp{get;set;}
    public String PAccountNumber{set;get;}
    public ApexPages.StandardController stdController;
   
    public OppAutoPopulateCTRL (ApexPages.StandardController controller)
    {
        stdController = controller;
        opp= new Opportunity();
       
    }

   //Added to autopopulate the values
    public void autoPopulate()
    {   
            
              Opportunity opp =  (opportunity) stdController.getRecord();   
              List<Account> acc = new List<Account>();
              Acc = [
                             SELECT Id, Name, AccountNumber,Zip_Code__c
                             FROM Account
                             WHERE id =: opp.AccountId
                   ];
              System.debug('@@'+acc.size() );
            
               
             Opp.MainCompetitors__c = acc[0].Name;             
            
   }
}
SarfarajSarfaraj
Hi

Use this code,

<apex:page standardController="Opportunity" extensions="OppAutoPopulateCTRL"  id="page">
   
    <apex:form id="myForm" >
        <apex:pageBlock mode="edit" >
           
            <apex:pageblocksection title="LMS Lookup" id="Contractsec1">
              
            <apex:pageblocksectionItem > 
              <apex:actionRegion >
              <apex:inputfield value="{!Opp.AccountId}" >
                 <apex:actionSupport event="onchange" action="{!autoPopulate}" reRender="panelConType"/>
               </apex:inputfield>     
               </apex:actionRegion>
          </apex:pageBlockSectionItem>
      
</apex:pageblocksection>
</apex:pageBlock>
<apex:pageBlock title="Popup">     
      <apex:pageblocksection >
<!--   Added to auto populate   -->
          <apex:pageblocksectionItem id="popup1" >        
             <apex:outputLabel value="{!$ObjectType.Opportunity.fields.MainCompetitors__c.label}" />

                 <apex:outputPanel id="panelConType" >
                     <apex:inputfield value="{!Opportunity.MainCompetitors__c}" />
                 </apex:outputPanel>
                 </apex:pageblocksectionItem>                
                <apex:inputfield value="{!Opportunity.CloseDate}" />
                <apex:inputfield value="{!Opportunity.StageName}" />
                <apex:inputfield value="{!Opportunity.Name}" />
                </apex:pageblocksection> 
    <apex:pageblockbuttons >
                    <apex:commandButton action="{!save}" value="Save" id="theButton"/>
      </apex:pageblockbuttons>
</apex:pageBlock>
  </apex:form>
</apex:page>
public class OppAutoPopulateCTRL {

    public Opportunity opp{get;set;}
    public String PAccountNumber{set;get;}
    public ApexPages.StandardController stdController;
   
    public OppAutoPopulateCTRL (ApexPages.StandardController controller)
    {
        stdController = controller;
        opp =  (opportunity) stdController.getRecord();   
    }

   //Added to autopopulate the values
    public void autoPopulate()
    {   
            
              List<Account> acc = new List<Account>();
              Acc = [
                             SELECT Id, Name, AccountNumber
                             FROM Account
                             WHERE id =: opp.AccountId
                   ];
              System.debug('@@'+acc.size() );
            
               
             Opp.MainCompetitors__c = acc[0].Name;             
            
   }
}