0

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)?

Bhushan Lodha
  • 6,824
  • 7
  • 62
  • 100

3 Answers3

1

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

Gerard Sexton
  • 3,114
  • 27
  • 36
0

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;
}
mast0r
  • 820
  • 5
  • 13
  • actually I want my field to be custom field in Accounts. I am pretty new to sfdc – Bhushan Lodha Aug 24 '12 at 13:18
  • But why do you want to fill this list with data from another source? I mean that values in a custom fields (picklist) are stored in salesforce database. – mast0r Aug 24 '12 at 13:24
  • What do you mean with dynamically generated from other object. What object? – mast0r Aug 24 '12 at 13:37
  • I think he is referring to the picklist values. When you add a picklist you set all the values there and then. He wants to know if you can do it dynamically. – Gerard Sexton Aug 27 '12 at 07:48
0

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
Bhushan Lodha
  • 6,824
  • 7
  • 62
  • 100