Skip to main content
9 answers
  1. Jun 24, 2018, 7:02 AM
    Here is the updated code based on your requirememt:

     

    Page:

    <apex:page controller="ProductController">

    <apex:form >

    <style>

    .round3 {

    border: 2px grey;

    border-radius: 5px;

    }

    </style>

    <apex:pageBlock >

    <apex:pageBlockSection columns="1">

    <apex:actionFunction name="updateFun" action="{!doNothing}" rerender="pb"/>

    <apex:selectList value="{!strFamily}" size="1" multiselect="false" styleClass="round3">

    <apex:selectOptions value="{!lstOptions}"> &nbsp;<br/>

    </apex:selectOptions>

    </apex:selectList>

    </apex:pageBlockSection>

    <apex:pageBlockSection columns="1">

    <apex:commandButton value="Click Here To Get The Results" style="padding: 3px 15px;" onclick="updateFun()" reRender="pb"/>

    </apex:pageBlockSection>

    </apex:pageBlock>

    <apex:pageBlock id="pb">

    <apex:pageBlockTable value="{!ProductRecords}" var="pr">

    <apex:column >

    <apex:facet name="header" > Product Name </apex:facet>

    <apex:outputlink value="/{!pr.Id}">{!pr.Name}</apex:outputlink> <br/>

    </apex:column>

    <apex:column value="{!pr.ProductCode}"/>

    <apex:column value="{!pr.family}"/>

    </apex:pageBlockTable>

    </apex:pageBlock>

    </apex:form>

    </apex:page>

    Controller:

    public class ProductController {

    public String strFamily {get;set;}

    public List<SelectOption> lstOptions {get;set;}

    public Product2 prd {get;set;}

    Public List<Product2> lstProducts {get;set;}

    public ProductController() {

    prd = new Product2();

    strFamily = '';

    lstOptions = new List<SelectOption>();

    lstProducts = new List<Product2>();

    Schema.DescribeFieldResult familyDesc = Product2.Family.getDescribe();

    List<Schema.PickListEntry> lst5 = familyDesc.getPickListValues();

    for(Schema.PickListEntry obj:lst5){

    lstOptions.add(new SelectOption(obj.getLabel(),obj.getValue()));

    }

    }

    public void doNothing() {

    system.debug('Value after change is'+strFamily);

    }

    public List<Product2> getProductRecords() {

    lstProducts = [Select id, ProductCode,Family, Name From Product2 Where Family =:strFamily];

    return lstProducts;

    }

    }

    Mark my answer best if it solves your problem :)