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
Ravi PrabhuRavi Prabhu 

SOQL not executing in Apex custom controller

Hi,
I have a VF page which contains 1 page block. There are 2 fields in page block one is date and another is name. When user select the date and name and click on button,  the page has to display records from custom object. 

The value of date and name is passed to controller and SOQL query
need to fetch the data from customobject

The name field is a dropdown, dropdown values are fetched from picklist values of name field which is working fine.

The issue here is when i click the button nothing is happening.  the debug log shows that SOQL query is not running.

Also after display of records on page user need to select the records and should be able to delete. Please help with this code as well.
Visualforce page

<apex:page id="pageID" Controller="TestPageBlock2Cont"   showHeader="false" tabStyle="Ticket_Effort_Category__c" >
    <script>
  		document.title = "AMS Reporting";
	</script>
    <script>

    <!--validate input fields in summary section-->
    <script>
    	function validatechk(){
	        var chk2 = document.getElementById("{!$Component.pageId.formId.pgblock2.pgblocksection2.selectedlist}").value;
			if(chk2 == ' '){
				alert("Please select the name")
			}
    	}
	</script>
    <style type="text/css">
     .activeTab {background-color: #236FBf;  color:white; background-image:none}
     .inactiveTab { background-color: white; color:black; background-image:none}
    	body{background-color: #F8F8FF;}
       .bPageBlock {background-color: #778899 ;}
        .bAlign {text-align:center;}
    </style>
    
    <apex:panelGrid columns="2" width="100%">
        <apex:panelGrid columns="1" width="100%">
			<img src="{!$Resource.logo1}" width="100px" height="100px" align="left"/>
        </apex:panelGrid>

        <apex:outputlabel style="font-style:regular; font-weight:bold; font-size:30px; 
                                 font-family:Helvetica; color:DodgerBlue;" 
                          value="AMS Reporting" />

    </apex:panelGrid>
    <apex:form id="formId" styleClass="myFormStyle" >

   <apex:actionRegion >    
    <!--Summary section -->    
	<apex:pageBlock id="pgblock2" title="Summary"   >
        <apex:pageBlockSection id="pgblocksection2" >
        <apex:OutputPanel >
         <apex:panelGrid columns="5">
             <apex:outputLabel style="font-style:regular; font-weight:bold; font-size:11px; 
                                      font-family:Helvetica;" >
                                      Date </apex:outputLabel>
             <apex:inputField value="{!sumtktRecord.Date__c}" ></apex:inputField>
             <apex:outputLabel style="font-style:regular; font-weight:bold; font-size:11px; 
                                      font-family:Helvetica;" >
                                      Select Assigned Person </apex:outputLabel>
             <apex:selectList id="selectedlist" value="{!sumtktRecord.responsible__c}"
                              size="1" multiselect="false" style="margin-right:10px;" >
                <apex:selectOptions value="{!ListOfUser}" />
             </apex:selectList>
              <apex:commandButton action="{!getsummarylist}" value="Go" immediate="true"
                                  onclick="validatechk();" rerender="msgsS" >
             </apex:commandButton>
        </apex:panelGrid>           
        </apex:OutputPanel>
         </apex:pageBlockSection>

        <!--Summary-->
        <apex:pageBlockTable value="{!fetchlist}" var="I"  id="msgsS" >
            <apex:column headervalue="Date" > 
	            <apex:outputField value="{!I.Date__c}"/>
            </apex:column>
            <apex:column headervalue="Ticket Number">
            	<apex:outputField value="{!I.Ticket_Number__c}"/>
            </apex:column>
             <apex:column headervalue="Division" >
                 <apex:outputField value="{!I.Division__c}"/>
            </apex:column>
             <apex:column headervalue="Application" >
                 <apex:outputField value="{!I.Application__c}"/>
                 </apex:column>
             <apex:column headervalue="Responsible" >
                 <apex:outputField value="{!I.Responsible__c}"/>
                 </apex:column>
             <apex:column headervalue="Effort" >
                 <apex:outputField value="{!I.Effort__c}"/>
                 </apex:column>
        </apex:pageBlockTable>
       </apex:pageBlock>   
        </apex:actionRegion>
    </apex:form>
</apex:page>

Apex controller

public class TestPageBlock2Cont {
    public list<Ticket_Effort_Category__c> fetchList{get;set;}
    public list<Ticket_Effort_Category__c> userList{get;set;}
    public Ticket_Effort_Category__c sumtktRecord{set;get;}
    public String selecteduserId {get;set;}
    public Date selectedDate {get;set;}
    List<SelectOption> selectOptions{get;set;}
  
    public TestPageBlock2Cont() {
       		 fetchList = new list<Ticket_Effort_Category__c>(); 
      		 sumtktRecord = new Ticket_Effort_Category__c(); 
   		 selecteduserId = sumtktRecord.Responsible__c;
        	 selectedDate = sumtktRecord.Date__c;
 	}

    public void getsummarylist(){
        	fetchList = [select id, Date__c, ticket_number__c, Division__c, Application__c, 
                Responsible__c, Effort__c 
                     from Ticket_Effort_Category__c 
                     where Responsible__c = :selecteduserId and
                     	   Date__c = :selectedDate];
    }       
	
    public List<SelectOption> getListOfUser(){
         selectOptions = new List<SelectOption>();
         selectOptions.add(new SelectOption( ' ' ,'---Select---'));
     	 Schema.DescribeFieldResult describeResult = 
         Ticket_Effort_Category__c.Responsible__c.getDescribe();
      	List<Schema.PicklistEntry> pickListEntries = describeResult.getPicklistValues();
      	for( Schema.PicklistEntry eachEntry : pickListEntries) {
         selectOptions.add(new SelectOption(eachEntry.getLabel(), eachEntry.getValue()));    
      	}
        return selectOptions;
}
}






 
David Zhu 🔥David Zhu 🔥
You may need to do the following:
<apex:commandButton  value="Go" immediate="true" onclick="validatechk();return false;" rerender="msgsS" >

Add this line:
<apex:actionFunction name="getsummarylist" action="{!getsummarylist}"/>

Add a line in js function:
        function validatechk(){
            var chk2 = document.getElementById("{!$Component.pageId.formId.pgblock2.pgblocksection2.selectedlist}").value;
            if(chk2 == ' '){
                alert("Please select the name")
            }
            else {
                getsummarylist();
            }
        }