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
lovetolearnlovetolearn 

Help with Setter and Getter Method

Hi, 

 

I am trying to return the number of records associated with the user input. Here is my VF markup:

 

<apex:page standardController="SFDC_Employee__c" extensions="myTextController" >
    <apex:form >
        <apex:pageblock >
            <apex:pageblockSection >
                <apex:inputText id="myText" value="{!myText}" label="Employee Name">
                    <!---<apex:actionSupport event="onclick" reRender="display"/>--->
                </apex:inputText><br/>
                <apex:commandButton value="Display" reRender="display"/><br/><br/>  
                <apex:outputPanel id="display">
                    <apex:outputText value="You entered: {!ListSize}" style="font-weight:bold"/><br/><br/>
                </apex:outputpanel>
            </apex:pageblockSection> 
        </apex:pageblock>
    </apex:form>
</apex:page>

 

And here is my Apex class:

 

public class myTextController {
    
    public myTextController(ApexPages.StandardController controller) {
    }
    
    public String myText {get; set;}
    List<Schedule_Days_Off__c>sdolist=[SELECT Name FROM Schedule_Days_Off__c WHERE Employee_Name__r.Name =: myText];
    Integer x = sdolist.size();
    
    public Integer getListSize(){
        return x;
    }

}

 

The List returns values when I specific a certain name. For instance, if I change the SOQL statement to SELECT NAME FROM SCHEDULE_DAYS_OFF__C WHERE EMPLOYEE_NAME__R.NAME = 'TEST USER.' The List size is not 0. But when I do EMPLOYEE_NAME__R.NAME =: myText, and enter Test User on the VF page. The List size is 0. I think it may be my setter method, but I am not sure. Please help. Thank you. 

Best Answer chosen by Admin (Salesforce Developers) 
SFDC_EvolveSFDC_Evolve

Please try the below  code ... I used the Account Object in place of SFDC_Employee__c

 

public class myTextController {

public String myText {get; set;}

public myTextController(ApexPages.StandardController controller) {
}

public Integer getListSize(){
List<Account> sdolist=[SELECT Name FROM Account WHERE Id =: myText];
return sdolist.size();
}

}

 

Please mark it  resolved .. if the issue is solved....:)

 

Thanks

SFDC_Evolve

All Answers

SFDC_EvolveSFDC_Evolve

Please try the below  code ... I used the Account Object in place of SFDC_Employee__c

 

public class myTextController {

public String myText {get; set;}

public myTextController(ApexPages.StandardController controller) {
}

public Integer getListSize(){
List<Account> sdolist=[SELECT Name FROM Account WHERE Id =: myText];
return sdolist.size();
}

}

 

Please mark it  resolved .. if the issue is solved....:)

 

Thanks

SFDC_Evolve

This was selected as the best answer
lovetolearnlovetolearn

Thank you.