+ Start a Discussion
sfdclivesfdclive 

regarding dynamic apex

Hi,

I have one object(account) with a picklist field location__c having values us,uk,india,china. if i select any picklist value,  records will be displayed as a table

 

please help me, I am new to salesforce

 

 

regards

sri

 

 

Bhawani SharmaBhawani Sharma
You need to write a method in your controller class. Write a query to find all the account where Location__c =: selectedLocation.
Use actionSupport to invoke this method
Advanz Knowledge SystemsAdvanz Knowledge Systems

HI 

 

      Use   <apex:actionSupport >tag   for this requirement , Please go through the below  sample code , 

 

Visualforce and its controller

 

============================================================

 <apex:page controller="Recinpicklist1">
<apex:form >

<apex:pageBlock >
<apex:selectList value="{!selectop}"  size="1"  >
<apex:actionSupport id="pbid" event="onchange" reRender="rr" />
        <apex:selectOptions value="{!records}" > </apex:selectOptions>
        </apex:selectList>
        
    
        <apex:dataTable value="{!selectpickvalue}" var="a" rendered="{!pb1}" id="rr" >
        <apex:column value="{!a.Phone}" headerValue="Phone"/>
        <apex:column value="{!a.Name}" headerValue="Name"/>
        </apex:dataTable>
       
        </apex:pageBlock>
        </apex:form>
</apex:page>
 
 
 
 
public with sharing class Recinpicklist1 {
 
       public String records {  set; }

  // public String course { get; set; }
     boolean x;
   public Boolean getPb1() {
       return x;
   }

public Recinpicklist1 (){
x=true;
}
   public boolean pb1 {  set; }

   

   public list<Contact> getSelectpickvalue() {
   li=[select id,Name,Phone from Contact where name=:selectop ];
       return li;
   }


   public Contact selectpickvalue {  set; }

   public String selectop { get; set; }
List<Contact> li;
   public List<selectoption> getRecords() {
   li=[select Name,Phone from Contact];
   for(Contact c:li){
   p.add(new selectoption(c.name,c.name));
   }
       return p;
   }
List<selectoption> p= new List<selectoption>();


}