You need to sign in to do that
Don't have an account?
PrasadVR
Displaying records based on the pick list values
Hello.....
Here my requriment is i want to display records based on pick list values, it means if i select all accounts means i want to display all accounts, suppose if i select my accounts means i want to display that accounts only how can we achive this using Apex..........
Hi Naidu,
If you are aware that salesforce has given that default fucntionality, incase you still want with apex then for
My Account write a query - > list<Account> listAccounts = [Select name from Account where Owner=:userId (currently logged in user) ];
All accounts --> list<Account> listAccounts = [Select name from Account ];
Hope this helps.
Thanks,
Pinto
Hello Pinto,
Here My Doubt is When ever i select all accounts in picklist at that time it needs to call that all accounts query how can we achive this.
Hi,
Create a
public list<Account> listAccounts {get;set;}
if(picklist=='AllAccounts'){
listAccounts = [Select name from Account ];
}
else if(picklist=='AllAccounts'){
listAccounts = [Select name from Account where Owner=:userId (currently logged in user) ];
}
bind this listAccounts in the visualforce page and iterate using the repeat.
Hello Pintos,
I wrote this pice of code but its not working fine, can u check it once..
public with sharing class accountcls {
public string picklist {get;set;}
public list<account> lstcon { get; set; }
public List<SelectOption> items{get; set;}
public String selectedAccount{get; set;}
public string AllAccounts {get;set;}
public accountcls(){
items = new List<SelectOption>();
items.add(new selectoption ('All Accounts','All Accounts'));
items.add(new selectoption ('MY Accounts','MY Accounts'));
items.add(new selectoption ('Last Accounts','AllOpen Accounts'));
items.add(new selectoption ('Last Accounts','AllClosed Accounts'));
items.add(new selectoption ('Last Accounts','Recently Viewed Accounts'));
items.add(new selectoption ('Last Accounts','Recently Modified Accounts'));
}
public void getContacts(){
System.debug('--selectedAccount------->'+selectedAccount);
if(picklist=='AllAccounts'){
List<account> lstcon = [Select id, name from account];
}
}
}
vfpage
<apex:page controller="accountcls">
<apex:sectionHeader title="Accounts" subtitle="HOME"/>
<apex:form >
<apex:outputtext style="height:5000px;font-weight:bold" value="View:"/>
<apex:selectlist value="{!selectedAccount}" size="1">
<apex:selectOptions value="{!items}"/>
<apex:actionSupport event="onchange" action="{!getContacts}" status="stat" rerender="out"/>
</apex:selectlist> <br/> <br/>
<apex:outputPanel id="out">
<apex:pageBlock >
<apex:pageBlockTable value="{!lstcon}" var="lst">
<apex:column value="{!lst.name}"/>
<apex:column value="{!lst.phone}"/>
<apex:column value="{!lst.type}"/>
</apex:pageBlockTable>
</apex:pageBlock>
</apex:outputPanel>
</apex:form>
</apex:page>
I would like to display the detail page of a record in the same vf page when I choose a record from the picklist. For example, when I choose "Record A" of Account object from the picklist , it should display the detail page of "Record A" just below. can someone assist me , how could I do that ??
try this
Page
<apex:page standardController="contact" extensions="Example4SelectdList" >
<apex:form id="theform" >
<apex:pageBlock id="theblock" >
<div style="width:700px; margin:0 auto;">
<apex:outputText value="List of Contacts : "/>
<apex:selectList value="{!selectedItemValue}" multiselect="false" size="1">
<apex:actionSupport event="onchange" action="{!changeRec}" status="thestatus" reRender="theform" />
<apex:selectOptions value="{!items}"/>
</apex:selectList>
</div>
</apex:pageBlock>
<apex:actionStatus id="thestatus" startText="Please Wait It's Loading....."></apex:actionStatus>
<apex:detail subject="{!recId}" rendered="{!if(recId!=null,true,false)}" relatedList="false" />
</apex:form>
</apex:page>
Controller
public class Example4SelectdList {
public string selectedItemValue{get;set;}
public Id recId{get;set;}
/* // to hard code the picklist values
public List<SelectOption>items {get {
if(items==null){
items = new List<Selectoption>();
items.add(new selectoption('1','One'));
items.add(new selectoption('2','Two'));
items.add(new selectoption('3','Three'));
return items;
}
return null;
}
set;}
*/
public Example4SelectdList(ApexPages.StandardController controller) {
}
// to add 10 contacts to dropdown list
public List<Selectoption> getItems(){
List<Selectoption> opts = new List<Selectoption>();
opts.add(new selectoption('','--None--'));
for(Contact con : [Select Id,Name From Contact limit 10]){
opts.add(new selectoption(con.Id,con.Name));
}
return opts;
}
public pageReference changeRec(){
System.debug('===selectedItemValue==='+selectedItemValue);
if(selectedItemValue!=null&&selectedItemValue!=''){
recId = selectedItemValue;
}
else recId = null;
return null;
}
}
That's worked :) Kudos..
Thanks for sharing the knowledge with us, its really helpful.
I am not able to replicate the above with order object. Can you help me?