As the subject reads, I have several use cases where it would be really useful to change the values in a picklist to only include certain values when data in another object changes, is this possible to do from within a trigger?

e.g. Update a picklist of active employees when people leave or join the company.

有帮助吗?

解决方案

Out of the box - no.

Picklists can be controlled with Metadata API (and in future maybe Tooling API too) - but from Apex point of view you need a callout. Either to external system that'll leverage the Metadata API or have a look at Adding Columns dynamically to Salesforce Reports - there's an interesting "mdapi" plugin that you might decide to use. Bear in mind destructive changes (like removal of values) are pretty annoying to execute...

In this particular example it's very tempting to say "you're doing it wrong" :(

  1. A lookup to User will out of the box hide users that aren't active. Problem solved.
  2. What are you going to do when the organisation will grow (through acquisitions?) and you'll hit the limit of max 1000 picklist values? http://help.salesforce.com/apex/HTViewHelpDoc?id=picklist_limitations.htm (probably even sooner depending how much of the 15K limit you've used already)
  3. Personally I consider a picklist with anything more than 50 entries a crappy UI / user experience. Well, unless there's some kind of autocomplete paired with it. Scroll, scroll, scroll...
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top