如何描述(枚举)对 Salesforce 中特定记录类型有效的选项列表实体?

发布于 2024-12-10 11:36:56 字数 480 浏览 0 评论 0原文

在 apex 代码中,我想枚举选项列表字段的合法值。为此,我只需调用 Account.Foobar__c.getDescribe().getPickListValues() 即可获得 Schema.PickListEntry 值的列表。

但是,可以为给定的 sObject 设置多个记录类型。例如,帐户可能具有“制造商”、“分销商”和“零售商”记录类型。在 Salesforce 设置中,可以根据记录类型编辑(限制)每个字段的选项列表条目。因此,零售商类型帐户可能仅使用 Foobar 字段的选项列表值的子集。

所以基本上我想要 Account.Foobar__c.getDescribe().getPickListValues('Retailer') 但这不是语法。 validFor 方法看起来很有前途,但它似乎仅适用于字段相关选项列表 - 仅按记录类型过滤的选项列表对于 isDependentPicklist 返回 false。

In apex code I want to enumerate the legal values for a picklist field. To do this I can just call Account.Foobar__c.getDescribe().getPickListValues() and I've got a list of Schema.PickListEntry values.

However it's possible to setup multiple record types for a given sObject. For example Account might have "Manufacturer", "Distributor" and "Retailer" record types. In the Salesforce setup it is possible edit (limit) the picklist entries for each field based on record type. So Retailer type accounts might only use a subset of the picklist values for the Foobar field.

So basically I want Account.Foobar__c.getDescribe().getPickListValues('Retailer') however this is not the syntax. The validFor method looks promising, but it seems like it is only for field dependent picklists - a picklist filtered only by record type returns false for isDependentPicklist.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

恰似旧人归 2024-12-17 11:36:56

我知道这是一篇旧帖子,但也许下面的信息会对仍然需要答案的人有所帮助。

我发现这里< /a> 实际上可以通过调用describeLayout() 来获取记录类型特定选项列表值的列表。

使用您的示例 (C#):

DescribeLayoutResult result = binding.describeLayout("Account", new string[] { "01230000000xxXxXXX" } );
PicklistEntry[] values = result.recordTypeMappings[0].picklistsForRecordType[12345].picklistValues;
  • 将“01230000000xxXxXXX”替换为您的零售商记录类型对象的 RecordTypeId。使用查询“SELECT Id FROM RecordType WHERE Name = 'Retailer'”来获取值。
  • 12345 替换为您想要获取其值的选项列表对象的索引。

I know this is an old post, but maybe the info below will help someone who still needs the answer.

I found here that one can actually get a list of record type specific picklist values by making a describeLayout() call.

Using your example (C#):

DescribeLayoutResult result = binding.describeLayout("Account", new string[] { "01230000000xxXxXXX" } );
PicklistEntry[] values = result.recordTypeMappings[0].picklistsForRecordType[12345].picklistValues;
  • Replace "01230000000xxXxXXX" with a RecordTypeId of your Retailer record type object. Use the query "SELECT Id FROM RecordType WHERE Name = 'Retailer'" to get the value.
  • Replace 12345 with an index of your picklist object that you would like to get values of.
南冥有猫 2024-12-17 11:36:56

不幸的是,你不能在纯粹的 Apex 中做到这一点。元数据 API 确实公开了它。

相关意见:http://boards.developerforce.com/t5/Apex-Code-Development/Any-way-to-obtain-picklist-values-by-record-type/td-p/287563

You can't do it in pure Apex AFAIK, unfortunately. The metadata API does expose it.

Related opinions: http://boards.developerforce.com/t5/Apex-Code-Development/Any-way-to-obtain-picklist-values-by-record-type/td-p/287563

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文