function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
vjenvjen 

Values in multi-select Picklist from a query

Hi,

 

I am new to salesforce.com.

 

When I create a customer Account field with multi-select Picklist data type, can I have the values from a query of my account data? In this case, I want to show in the list of all accounts that match a specific Account Type.

 

Do I have to wrote some code to do this? I'd appreciate if someone can point me to some 101 course to learn how to do it.

 

-- vj

Best Answer chosen by Admin (Salesforce Developers) 
SidzSidz

Vj,

 

The values in a picklist or the definition of a picklist is part of salesforce.com metadata(metadata has the information about the object structure, fields , definitions , etc) and this is usually  modified using configuration.

The picklist values cannot be dynamically changed with respect to the data .

 

It is not a good design to change metadata frequently, 

 

To go with a simple design , without having to build a custom solution , create 3 lookup( a lookup field allows you to link your current record to any salesforce.com object) fields to account

and you can define lookup filters(add the conditions like account type='Supplier - partner') on the field.

you can probably put a validation rule to ensure that all 3 lookup fields don't hold the information of same account.
 

The other approach would be to design a custom solution where you need to build a visual force page where you query the top three suppliers and allow the user to select them and store the information of these accounts in a custom object or 

store the information on some text area field on account.

 

To over complicate the requirement , you can always override the "edit " and "new" pages and create visual force pages for them, with the required custom functionalities.

 

 

hope this helps.
(please select the relevant  answer as "marked as solution")

 

Thanks,

Sidz

All Answers

SidzSidz

Hi,

 

Your question is not clear.
do you want to show all the accounts which have a particulat account type?do you want this functionality on a visual force page or on the list view? 

were you asking about populating the list of values in a multiselect picklist by querying the account data?

 

please provide more details.

 

Thanks,

Sidz

Navatar_DbSupNavatar_DbSup

Hi,
You can do this through Apex but you have to bind the value with the string type variable.

Try the below code as reference:


<apex:page controller="sampleCon">
<apex:form>
<apex:selectCheckboxes value="{!countries}" title="Choose a country">
<apex:selectOptions value="{!items}"/>
</apex:selectCheckboxes><br/>
<apex:commandButton value="Test" action="{!test}" rerender="out" status="status"/>
</apex:form>
<apex:outputPanel id="out">
<apex:actionstatus id="status" startText="testing...">
<apex:facet name="stop">
<apex:outputPanel>
<p>You have selected:</p>
<apex:dataList value="{!countries}" var="c">a:{!c}</apex:dataList>
</apex:outputPanel>
</apex:facet>
</apex:actionstatus>
</apex:outputPanel>
</apex:page>

/*** Controller: ***/
public class sampleCon {
String[] countries = new String[]{};

public PageReference test() {
return null;
}

public List<SelectOption> getItems() {
List<SelectOption> options = new List<SelectOption>();
options.add(new SelectOption('US','US'));
options.add(new SelectOption('CANADA','Canada'));
options.add(new SelectOption('MEXICO','Mexico'));

return options;
}

public String[] getCountries() {
return countries;
}

public void setCountries(String[] countries) {
this.countries = countries;
}
}

 

For more examples go through the link below:
http://www.interactiveties.com/b_visualforce_picklist.php

 

Did this answer your question? If not, let me know what didn't work, or if so, please mark it solved. 

Nilesh ManeNilesh Mane

This link gives you the exact solution.......

http://hisrinu.wordpress.com/2011/05/30/custom-multi-select-picklist-field-in-visualforce/

 

Hope this will help you...... :manhappy:

vjenvjen

Sidz,

 

This is what confused me a bit, there are many new terms that I am trying to lern. So here is what I want to do:

 

In my application, there is a custom multi-select picklist field called "top-3 suppliers" under Account. In this field, I want to show account names that were already in the account list and their account type matches a value called "supplier-partner." In our business, some of our customers are also our suppliers and they buy from each others.

 

When I do App Setup - Customize - Accounts - Fields then select Picklist (multi-select) data type, I can only enter values into the box. I want the picklist to show a list of account names described above for this field when a person creates a new account or updates an account.

 

-- vj

SidzSidz

Vj,

 

The values in a picklist or the definition of a picklist is part of salesforce.com metadata(metadata has the information about the object structure, fields , definitions , etc) and this is usually  modified using configuration.

The picklist values cannot be dynamically changed with respect to the data .

 

It is not a good design to change metadata frequently, 

 

To go with a simple design , without having to build a custom solution , create 3 lookup( a lookup field allows you to link your current record to any salesforce.com object) fields to account

and you can define lookup filters(add the conditions like account type='Supplier - partner') on the field.

you can probably put a validation rule to ensure that all 3 lookup fields don't hold the information of same account.
 

The other approach would be to design a custom solution where you need to build a visual force page where you query the top three suppliers and allow the user to select them and store the information of these accounts in a custom object or 

store the information on some text area field on account.

 

To over complicate the requirement , you can always override the "edit " and "new" pages and create visual force pages for them, with the required custom functionalities.

 

 

hope this helps.
(please select the relevant  answer as "marked as solution")

 

Thanks,

Sidz

This was selected as the best answer