Skip to main content
Blair Waldorf a posé une question dans #Collaboration
I am a beginner just started learning how to code. Would be great if somebody helped me understand how do I

 

> populate the Department field into my query dynamically depending on the user input.

 

VF page:

 

<apex:page Controller="ContactByDeptClass">

 

<apex:pageBlock title="Contact">  

 

<apex:form >

 

<apex:pageBlockSection columns="2">

 

    <apex:pageBlockSectionItem >

 

        <apex:outputLabel >Department</apex:outputLabel>

 

            <apex:inputField value="{!con.Department__c}"/>

 

    </apex:pageBlockSectionItem>

 

    <apex:pageBlockSectionItem >

 

        <apex:outputLabel >Month</apex:outputLabel>

 

            <apex:selectList value="{!SelectMonth}" multiselect="false" size="1">

 

                <apex:selectOption itemValue="" itemLabel=" --None--"/>

 

                <apex:selectOption itemValue="1" itemLabel="January"/>

 

                <apex:selectOption itemValue="2" itemLabel="February"/>

 

                <apex:selectOption itemValue="3" itemLabel="March"/>

 

            </apex:selectList> 

 

    </apex:pageBlockSectionItem>   

 

</apex:pageBlockSection>

 

</apex:form>

 

<apex:pageBlockTable value="{!KContacts}" var="item">

 

    

 

    <apex:column headerValue="First Name">

 

        <apex:outputLink value="/{!item.Id}">{!item.FirstName}</apex:outputLink>

 

    </apex:column>

 

    <apex:column value="{!item.LastName}"/>

 

    <apex:column value="{!item.Department__c}"/> 

 

    <apex:column value="{!item.Birthday__c}"/>    

 

</apex:pageBlockTable>

 

</apex:pageBlock>

 

</apex:page>

 

Controller:

 

public class ContactByDeptClass {

 

Public List<Contact> KFContacts;

 

Public Contact con{get;set;}

 

Public String SelectMonth {get;set;}

 

   

 

    public List<Contact> getKContacts() {

 

        

 

KFContacts = [SELECT FirstName, LastName, Department__c,Birthday__c FROM Contact where Firm_Contact_Status__c = 'Active'];

 

        

 

        return KFContacts;

 

       

 

       

 

    }

 

}
3 réponses
0/9000