You need to sign in to do that
Don't have an account?
Hero285Link
Show my Account.Name as a Picklist o search in my VFP
Hello everyone,
Im new In this Environment and I had been stuck for several hours,,
my question is...
Is it possible to take my field Name(Text), From my object Account,, and display it on my Visual Force Page as a PickList or as a SearchPanel, where the user could easily choose a predefined Name from Account???
Hi,
Yes . you can do this. you can easily display account name as a picklist ,SelectOption is used in salesforce to create custom picklist.
------------------------------------Apex ------------------------
Public Class AccountController {
public String selectedAccId{get;set;}
public List<SelectOption> getAccountNames() {
List<SelectOption> accOptions= new List<SelectOption>();
accOptions.add( new SelectOption('','--Select--'));
for( Account acc : [select Id,name from Account ] ) {
accOptions.add( new SelectOption(acc.Id,acc.name)); /*SelectOption list takes two parameters one is value and other one is label .In this case account name as a label and Id is the value .*/
}
return accOptions;
}
}
---------------------------------Visual Force -----------------------
<apex:page controller="AccountController1">
<apex:form>
<apex:pageBlock title="Account Name">
<apex:selectList value="{!selectedAccId}" size="1"> <!-- selectedAccId store the selected label value as account Id of selected account name.-->
<apex:selectOptions value="{!AccountNames}" />
</apex:selectList>
</apex:pageBlock>
</apex:form>
</apex:page>
Please let me know if u have any problem on same and if this post helps u plz give KUDOS by clcik on star at left.
All Answers
Hi,
Yes . you can do this. you can easily display account name as a picklist ,SelectOption is used in salesforce to create custom picklist.
------------------------------------Apex ------------------------
Public Class AccountController {
public String selectedAccId{get;set;}
public List<SelectOption> getAccountNames() {
List<SelectOption> accOptions= new List<SelectOption>();
accOptions.add( new SelectOption('','--Select--'));
for( Account acc : [select Id,name from Account ] ) {
accOptions.add( new SelectOption(acc.Id,acc.name)); /*SelectOption list takes two parameters one is value and other one is label .In this case account name as a label and Id is the value .*/
}
return accOptions;
}
}
---------------------------------Visual Force -----------------------
<apex:page controller="AccountController1">
<apex:form>
<apex:pageBlock title="Account Name">
<apex:selectList value="{!selectedAccId}" size="1"> <!-- selectedAccId store the selected label value as account Id of selected account name.-->
<apex:selectOptions value="{!AccountNames}" />
</apex:selectList>
</apex:pageBlock>
</apex:form>
</apex:page>
Please let me know if u have any problem on same and if this post helps u plz give KUDOS by clcik on star at left.
Thank You Sr. It was really helpful ! =D