0

The client has an object with multiple fields. One field is to choose an account. Another field is customer type. Customer type is currently a picklist, but the client wants to change it to a lookup on the account. Account is having a field called customer type. So in other words, they want to select an account, and expect the customer type to be auto populated after selecting the account. I am wondering what sort of field type is the best? I am thinking about a formula field, but not sure if that's the best choice.

1

A formula field is the way to ge here, it will automatically keep the value on the account in sync with the object(s) below the Account.

a simple TEXT(Acccount.CustomerType) should be sufficient !

https://trailhead.salesforce.com/en/content/learn/modules/advanced_formulas/picklist_formulas

2

If you are using standard functionality, then formulae field is good. But in case of visualforce or lightning, I would say to create apex:outputField or lightning:outputfield. When user choose account in Account lookup, fire onchange method on update of lookup value, invoke controller method and get the selected account and get the Customer type value for corresponding account using apex and populate the Customer type value in the field you created.

1

In my opinion, avoid code is always the best options. In this case, looks like that a Formula fields is a good solution for your requirement.

Also, you have a bunch of different approaches that you can follow, I can say some:

  1. A Process builder and a field
  2. A trigger

So, the decision should be made by yours.

1

Looking at your requirement, it seems that formula field is the way to go for you. But, before making that change, below are the things you should keep keep in mind.

As formula fields are not stored in the database rather are calculated when needed, it won't force any DML operations on the related records. Due to this reason,

  • Formula fields will not trigger a workflow - If you have a workflow on child object with rule criteria as Account Type ='ABC', and when you change the value of Account Type in Account object to ABC, the formula value in child object will change to ABC, but your workflow which was based on the above formula field won't fire as there was no DML which happened.
  • Formula fields cannot be used in Sharing rules
  • ​Formula fields are not searchable - You won't be able to search your child records based on the formula field.

So, if you don't have any of the above mentioned impacts, you can go ahead with the formula field approach.

1

Create a formula field on this object.

-If the Customer Type field of Account object is of Text type, then your formula should be: Acccount.CustomerType

-Else if Customer Type field of Account is of Picklist type, then your formula should be: TEXT(Acccount.CustomerType)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.