function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
KCarmenKCarmen 

How can I write a formula field to update fields based on a Picklist choice?

Hi all -

I have a Customer Object called PM Picks that is a Master-Detail relationship with the account. On the PM Picks, I have a picklist field that has our Product Lines. I also have other fields on the PM Pick pulling from the account such as #open opps, open opp amount, install base, etc. When someone chooses a product line, I would like the information for only the product chosen from the picklist to show up on the PM Pick record created. Basically, filtering the Account information based on product line. What is the best way to do this?
Best Answer chosen by KCarmen
pconpcon
In order to do what you want, you'll have to do the Visualforce route.  What you'll do is in the controller you'll have a get method for your fields.  When that get method is called in the rerender you'll then pull the information from the account object.  Unfortunatly you won't have access to your formula until the object is saved so you'll have to query the account in the controller to get the open_opp_amount__c field.

All Answers

pconpcon
Just to restate the problem, you have a picklist on your object.  When you choose something from this picklist you want only some fields to be available to fill out on your creation page.  For example if they choose "Farming" you want the "Livestock" field to appear but if they choose "Automotive" you want the "Garage" field to show?

If this is the case you pretty much have two options.

Record Types
This is the "easiest" option because the platform supports it the best and does not require any real development. (You may have to do a little URL hacking if you want to make creation a little eaiser).  To do this you would esentially change your Product Lines to be a Record Type on the PM Picks object.  Then you can create Layouts based on the Record Type and choose which fields you want to show / hide based on the Record Type

Pros
  • Very little development work
  • Can be done directly in production
  • Natively supported on the platform
Cons
  • Have to use the Record Type field instead of a custom named field
  • Managing Record Types is more difficult than managing a picklist
  • There are limits to the number of Record Types you have
  • You will have a layout per Record Type

Visualforce
This is the more complicated method, but will not require a change to your data structure.  For this you create a Visualforce page that overrides your new / edit page.  The Visualforce page includes inputFields for all of your fields on the object.  You then add a rendered flag to it to determine if it should be show for the picklist value.  The tricky bit here is maintaining the field list to picklist mapping in your controller as well as rerendering the entire page if the picklist is changed.

Pros
  • No changes to data model
  • Easier to customize / stylize
Cons
  • Not simple
  • Requires code deployment to change layout of new / edit page
  • Can be difficult to maintain the field to picklist mapping

If I'm way off base on what you're trying to do, let me know and I'll try again.
KCarmenKCarmen
Your right on base and thanks for the tips. I may have to end up trying both in my DEV just to hone my skills! LOL!
pconpcon
Great! If you don't mind marking this as solved so that it will be moved out of the unsolved queue it would make this much easier for others.
KCarmenKCarmen
Actually, that's only part of the problem solved. When a picklist value on my Custom Object is chosen, I want only filtered information based on values pulled from the Account record.  For example, if I chose Widget 1 as my product in the picklist on my Custom Object, I want only the Opportunity info accociated with Widget 1 to auto-populate (this information will come from roll-ups on the Account such as Open amount, total opp amount, etc). How can I get only the Open opp amount from Widget 1 to show in a field I have created in the Custom Object where the Picklist lives? I have the formula field "account__r.open_opp_amount__c" on there to populate on my Custom Object the total from the Account record but it's totaling from all opps, not the Widget 1

Record Types may not be a good solution for us because we have so many product lines but even if I decide to create Record Types for each product line, how can I get the formula fields within that record type to only populate on what that record type is for? I'm thinking I have to create a seperate roll-up for each Product line and insert into the appropriate Record Type.

 
pconpcon
In order to do what you want, you'll have to do the Visualforce route.  What you'll do is in the controller you'll have a get method for your fields.  When that get method is called in the rerender you'll then pull the information from the account object.  Unfortunatly you won't have access to your formula until the object is saved so you'll have to query the account in the controller to get the open_opp_amount__c field.
This was selected as the best answer
KCarmenKCarmen
Thanks, pcon - how do I mark this as solved. Sorry - I'm a newbie. :)