You need to sign in to do that
Don't have an account?
Lakshmi Gupta 4
Get Set method
I'm new to Salesforce and trying to understand Get, Set method. I have written this simple code, where user can search for a record from custom object Attendance. Set method is not assigning the value to variable "Keyword". Can someone explain what is the problem with my code?
Thank you
public class simplegetset
{
string keyword;
list <attendance__c> att;
public string getkeyword(){
return keyword;
}
public list <attendance__C> getatt(){
return att;
}
Public void setKeyword(string s){
keyword = s;
}
Public pagereference ShowResults(){
att = [select contact__c, Manager__c, Manager_s_Manager__c,
Approved__c,Attendance_Date__c, Hours__C,
Is_Eligible_for_compensatory_off__c, AttendanceType__c FROM Attendance__c where contact__C = :keyword];
return null;
}
}
============================================================================
<apex:page controller="simplegetset">
<apex:form >
<apex:pageblock title="List of Employee Attendance">
<apex:inputtext value="{!Keyword}"/>
<apex:commandButton value="Show Results" action="{!ShowResults}" rerender="details"/>
<apex:pageblockTable value="{!att}" Var="a" id="details">
<apex:column value="{!a.Contact__c}"/>
<apex:column value="{!a.Manager__c}"/>
<apex:column value="{!a.Manager_s_Manager__c}"/>
<apex:column value="{!a.Approved__c}"/>
<apex:column value="{!a.Attendance_Date__c}"/>
<apex:column value="{!a.Hours__c}"/>
<apex:column value="{!a.AttendanceType__c }"/>
</apex:Pageblocktable>
<apex:outputtext >{!keyword}
</apex:outputtext>
</apex:pageblock>
</apex:form>
</apex:page>
Thank you
public class simplegetset
{
string keyword;
list <attendance__c> att;
public string getkeyword(){
return keyword;
}
public list <attendance__C> getatt(){
return att;
}
Public void setKeyword(string s){
keyword = s;
}
Public pagereference ShowResults(){
att = [select contact__c, Manager__c, Manager_s_Manager__c,
Approved__c,Attendance_Date__c, Hours__C,
Is_Eligible_for_compensatory_off__c, AttendanceType__c FROM Attendance__c where contact__C = :keyword];
return null;
}
}
============================================================================
<apex:page controller="simplegetset">
<apex:form >
<apex:pageblock title="List of Employee Attendance">
<apex:inputtext value="{!Keyword}"/>
<apex:commandButton value="Show Results" action="{!ShowResults}" rerender="details"/>
<apex:pageblockTable value="{!att}" Var="a" id="details">
<apex:column value="{!a.Contact__c}"/>
<apex:column value="{!a.Manager__c}"/>
<apex:column value="{!a.Manager_s_Manager__c}"/>
<apex:column value="{!a.Approved__c}"/>
<apex:column value="{!a.Attendance_Date__c}"/>
<apex:column value="{!a.Hours__c}"/>
<apex:column value="{!a.AttendanceType__c }"/>
</apex:Pageblocktable>
<apex:outputtext >{!keyword}
</apex:outputtext>
</apex:pageblock>
</apex:form>
</apex:page>
All Answers
Update YOUR SOQL to check the like as shown below
When I remove the where clause and search for all the records in the above code. Display table is showing the name of the contact. So, I'm not sure how it is working.
Thanks a lot ! contact__r.name LIKE :'%'+keyword+'%' works!!