简体   繁体   English

Salesforce:具有动态价值的选择列表(多个)

[英]Salesforce: Picklist(multiple) with dynamic value

I have add custom field to Account with picklist(multiple) in Salesforce. 我已在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)? 如果不是,是否有可能从本机应用程序(用红宝石编写)中将值推入选择列表中?

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. 您可以做的是添加一个文本字段而不是一个选择列表,并使用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. 在visualforce中,显示自定义字段的选择列表并从控制器加载值。
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 可以在这里找到更详细的指南

Why dont't you use a normal SelectOption List in Apex? 为什么不在Apex中使用普通的SelectOption列表?

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;
}

I had to update picklist with values from my database (and not from some visualforce page). 我必须使用数据库(而不是某些visualforce页面)中的值更新选择列表。 So I authenticated account using Databasedotcom gem and it provides nice Api to iteract with Salesforce Objects (both Standard and Custom). 因此,我使用Databasedotcom gem验证了帐户,它为使用Salesforce Objects(标准和自定义)提供了很好的Api。

 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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM