0

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.

skirmish
  • 429
  • 4
  • 11

1 Answers1

1

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...
Community
  • 1
  • 1
eyescream
  • 18,088
  • 2
  • 34
  • 46
  • 1) Actually, we are in a pickle where we can't de-activate users because of record ownership, and until somebody manually transfers ownership (I hate that it has to be manual), then we have to leave them active. (2) We will never grow to more than about 200 in one org. (3) I'm right there with you, except I prefer 15 as a max before I think about something else. (4) I quite agree we're doing it wrong, but we've been using this since 2004 and I just recently walked into this and want to bring some structure to what we do.. – skirmish May 08 '14 at 14:59
  • Uh, I feel for you. Not even "Freeze" button can help you. How about adding a "almost inactive" checkbox to user and having a filtered lookup to user? If you can't change the UI now - maybe you can send yourself an email alert every time somebody flips that checkbox and then remove the picklist value manually... I would also consider going terrorist: "Dear business user(s) higher in Role hierarchy than this guy we want to deactivate, you have 1 week to redistribute these in your teams or I'll mass assign it all to you and problem solved" ;) – eyescream May 08 '14 at 19:45