Bhushan Lodha
Bhushan Lodha

Reputation: 6862

Salesforce: Picklist(multiple) with dynamic value

I have add custom field to Account with picklist(multiple) in Salesforce. But the values of picklist should be dynamically generated from other object. If not, is it possible to push values in picklist from native app(which is written in ruby)?

Upvotes: 0

Views: 8461

Answers (3)

Bhushan Lodha
Bhushan Lodha

Reputation: 6862

I had to update picklist with values from my database (and not from some visualforce page). So I authenticated account using Databasedotcom gem and it provides nice Api to iteract with Salesforce Objects (both Standard and Custom).

 client.authenticate :token => "my-oauth-token", :instance_url => "http://na1.salesforce.com"  #=> "my-oauth-token"

 account = client.materialize("Account")
 account_to_be_updated = account.find(account_id) # here account is same as Instance of Activerecord
 account_to_be_updated.my_picklist = [value1; value2; value3; value4]
 account_to_be_updated.save

Upvotes: 0

Gerard Sexton
Gerard Sexton

Reputation: 3210

I dont think the standard controller supports dynamically adding the possible picklist (select list) values.

What you could do is add a text field instead of a picklist and create a custom page with visualforce. Use the standard controller with an extension for your code. Create a new custom object for holding picklist values for a field (could be reused for other fields). Populate it with the possible picklist values.
In the page controller, load the values for that field.
In visualforce, display a picklist for the custom field and load the values from the controller.
Add an extra input field for manual insertion if desired.
On save, insert the value of the picklist (or input box) into the custom field.

A more detailed guide can be found here

Upvotes: 1

mast0r
mast0r

Reputation: 820

Why dont't you use a normal SelectOption List in Apex?

public List<SelectOption> getMyPicklist()
{   
    List<SelectOption> options = new List<SelectOption>();
    List<Account> acc = [ Select Id, Name From  Account Limit 10 ];

    for(Account a : acc){
        options.add(new SelectOption(a.Id,a.Name));
    }

    return options;
}

Upvotes: 0

Related Questions