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
ledap13ledap13 

If I press checkbox then the controller will be processed until the next cycle. Why?

Hi Friends,

 

can someone help me?

 

My controller:

public class contactExtension {
    private final Contact c; //User sobject
    private Opportunity oneopp {get;set;}
    public OpportunityContactRole  Oneoppid {get;set;}
    public List<cOpportunity> listOpportunity {get;set;}
    public List<Quote> listQuotes {get;set;}    
    public string optionacc{get;set;}
    public string optioncon{get;set;}
    public string optionquo{get;set;}      
    public string optionquoName{get;set;}      
    private string accountid {get;set;}
    Boolean showSecvar = false;
    Boolean showListvar = false;
    
    //initializes the private member variable u by using the getRecord method from the standard controller
    public contactExtension(ApexPages.StandardController stdController) {
        this.c = (Contact)stdController.getRecord();
    }
    

    public List<selectOption> getaccts() {
        List<selectOption> accts = new List<selectOption>();
            accts.add(new selectOption('', '- None -'));
            for (Account account : [SELECT Id, Name FROM Account]) {
            accts.add(new selectOption(account.id, account.Name));
        }
        return accts;
    }
    
    public List<selectOption> getconts() {
        List<selectOption> conts = new List<selectOption>();
            conts.add(new selectOption('', '- None -'));
            for (Contact contact : [SELECT Id, Name FROM Contact where accountid = :optionacc]) {
            conts.add(new selectOption(contact.id, contact.Name));
        }
        return conts;
    }     
    
   //select von Auswahlliste Contact
    public pagereference selectionCon(){
        getOpportunity();
        if (listOpportunity.size() >0) {
        showSection();
        }else{ApexPages.addMessage(new ApexPages.message(ApexPages.severity.INFO,'No available opportunities!!'));   
        dontshowSection();     
        }
        return null;
    }    

    public pagereference testmessage(){
        processSelected();
        ApexPages.addMessage(new ApexPages.message(ApexPages.severity.INFO,'Hello World !!'+optionquoName));
        return null;
    }
 
    public List<cOpportunity> getOpportunity() {
          if(listOpportunity == null) {
             listOpportunity = new List<cOpportunity>();
             for(Opportunity c: [SELECT ID,Name,StageName,Probability FROM Opportunity WHERE id in (Select OpportunityId From OpportunityContactRole where ContactId = :optioncon) LIMIT 50000]) {
                  listOpportunity.add(new cOpportunity(c));
             }
          }
          return listOpportunity ;
      }       


     public class cOpportunity {
          public Opportunity opp {get; set;}
          public Boolean selected {get; set;}
   
          //This is the contructor method. When we create a new cContact object we pass a Contact that is set to the con property. We also set the selected value to false
          public cOpportunity (Opportunity c) {
             opp = c;
             selected = false;
          }
      }
 
    public PageReference processSelected() {
          List<Opportunity> selectedOpportunity = new List<Opportunity>();
          for(cOpportunity cOpp: listOpportunity){
              if(cOpp.selected == true) {
                  selectedOpportunity.add(cOpp.opp);
                  
              }else{
              ApexPages.addMessage(new ApexPages.message(ApexPages.severity.INFO,'No Selected !!'));
              }
           }     
           
          showlistqoutes();
          if(listQuotes.size() > 0){
              showinflist();
          }
          
          System.debug('These are the selected Opportunity...');
          for(Opportunity opp: selectedOpportunity) {
              system.debug(opp);
              optionquo = opp.id;
              optionquoName= opp.Name;              
          }
          return null;
      }

        
    public pagereference showlistqoutes(){
        listQuotes = [SELECT QuoteNumber, Name, Discount FROM Quote WHERE OpportunityId=:optionquo LIMIT 50000];
        return null;
    }  
 

    public pageReference saveOpportinities() {
        try {
            List<Opportunity> OpportunityToUpdate = new  List<Opportunity>();
            for(cOpportunity cOpp: listOpportunity ) {
                if(cOpp.Selected) {
                    OpportunityToUpdate.add(cOpp.opp);
                }
            }     
            update OpportunityToUpdate;
        }
        catch(Exception ex) {
        apexPages.addMessage(new ApexPages.message(ApexPages.severity.ERROR,'The value for the field Last Name is already available !!'));
        }
        ApexPages.addMessage(new ApexPages.message(ApexPages.severity.INFO,'Record saved !!'));        
        return null;
    }    
      
    public void showSection() {showSecvar = true;}
    public Boolean getSectionshow(){return showSecvar;}  

    public void dontshowSection() {showSecvar = false;}
    public Boolean getdontshowSection(){return showSecvar;}     
    
    public void showInfList(){showListvar = true;}
    public Boolean getInfListshow(){return showListvar;}   
    
    public void dontshowInfList(){showListvar = true;}
    public Boolean getdontInfListshow(){return showListvar;}  
}

 

My Page:

 

<apex:page standardController="Contact" extensions="contactExtension" standardStylesheets="true">
<apex:pagemessages />
    <apex:sectionHeader title="Test für Trigger Quotes " subtitle="{!Contact.Name}" help="/help/doc/user_ed.jsp?loc=help"> </apex:sectionHeader>
    <apex:form >
    <apex:actionFunction name="myactionfun"  action="{!testmessage}"/>
        <apex:pageBlock mode="edit">
            <apex:pageBlockSection title="Accounts & Contacts" >
                <apex:pageBlockSectionItem >
                    <apex:outputLabel value="Account Name" for="acc" />
                    <apex:selectList id="acc" value="{!optionacc}" size="1" title="Account">
                        <apex:selectOptions value="{!accts}"/>
                        <apex:actionSupport event="onchange"/>
                    </apex:selectList>
                </apex:pageBlockSectionItem>
                <br/>
                <apex:pageBlockSectionItem >
                     <apex:outputLabel value="Contact Name" for="acc" />
                    <apex:selectList value="{!optioncon}" size="1" title="Account" >
                        <apex:selectOptions value="{!conts}" />
                        <apex:actionSupport event="onchange" action="{!selectionCon}"/>                         
                    </apex:selectList>
                </apex:pageBlockSectionItem>                   
            </apex:pageBlockSection>
            <apex:pageBlockSection title="Opportunities" rendered="{!sectionshow}" >
                <apex:commandbutton action="{!saveOpportinities}" value="Save"/>
                <br/>
                <apex:dataTable value="{!listOpportunity}" var="item" >
                  <apex:column >
                        <apex:facet name="header">{!$ObjectType.Opportunity.fields.Name.label}</apex:facet>
                        <apex:inputfield value="{!item.opp.Name}"></apex:inputfield>
                    </apex:column><apex:column >    
                        <apex:facet name="header">{!$ObjectType.Opportunity.fields.StageName.label}</apex:facet>                        
                        <apex:inputfield value="{!item.opp.StageName}"></apex:inputfield>
                    </apex:column><apex:column >   
                        <apex:facet name="header">{!$ObjectType.Opportunity.fields.Probability .label}</apex:facet>                         
                        <apex:inputfield value="{!item.opp.Probability }"></apex:inputfield>
                    </apex:column>
                    <apex:column headerValue="Test">
                        <apex:inputCheckbox value="{!item.selected}">
                         <apex:actionSupport event="onchange" action="{!testmessage}" />
                        </apex:inputCheckbox>     
                  </apex:column>           
                </apex:dataTable>                            
            </apex:pageBlockSection>  
            <apex:pageBlockSection title="Quote" rendered="{!InfListshow}" >
                <apex:commandbutton action="{!saveOpportinities}" value="Save"/>
                <br/>
                <apex:dataTable value="{!listQuotes}" var="item" >
                  <apex:column >
                        <apex:facet name="header">{!$ObjectType.Quote.fields.Name.label}</apex:facet>
                        <apex:inputfield value="{!item.Name}"></apex:inputfield>
                    </apex:column><apex:column >    
                        <apex:facet name="header">{!$ObjectType.Quote.fields.QuoteNumber.label}</apex:facet>                        
                        <apex:inputfield value="{!item.QuoteNumber}"></apex:inputfield>
                    </apex:column><apex:column >   
                        <apex:facet name="header">{!$ObjectType.Quote.fields.Discount .label}</apex:facet>                         
                        <apex:inputfield value="{!item.Discount }"></apex:inputfield>
                    </apex:column>
                </apex:dataTable>                            
            </apex:pageBlockSection>             
        </apex:pageBlock>
    </apex:form>
</apex:page>

Sonam_SFDCSonam_SFDC
What does the checkbox do? Could you please explain your use case and code a bit so we can understand what you are trying to do with the above code..