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
Chris High 6Chris High 6 

Isn't there a better way to evaluate many picklist values in an IF statement?

I feel like, despite searching and eliminating some options, I must be overlooking something that would make this a much cleaner formula in 2023. This State/Province is a picklist field, and if any of the following are selected on the parent record it drives this IF statement. This way of writing it WORKS and passes, but it's so prehistoric. Is there a better way yet?

IF(
AND(
SBQQ__ProductCode__c = '734000',
OR(
ISPICKVAL(SBQQ__Quote__r.State_Province__c,'TX'),
ISPICKVAL(SBQQ__Quote__r.State_Province__c,'NY'),
ISPICKVAL(SBQQ__Quote__r.State_Province__c,'VA'),
ISPICKVAL(SBQQ__Quote__r.State_Province__c,'NC'),
ISPICKVAL(SBQQ__Quote__r.State_Province__c,'KY'),
ISPICKVAL(SBQQ__Quote__r.State_Province__c,'AL'),
ISPICKVAL(SBQQ__Quote__r.State_Province__c,'NJ'),
ISPICKVAL(SBQQ__Quote__r.State_Province__c,'SC'),
ISPICKVAL(SBQQ__Quote__r.State_Province__c,'FL'),
ISPICKVAL(SBQQ__Quote__r.State_Province__c,'GA'),
ISPICKVAL(SBQQ__Quote__r.State_Province__c,'CA'),
ISPICKVAL(SBQQ__Quote__r.State_Province__c,'OK'),
ISPICKVAL(SBQQ__Quote__r.State_Province__c,'MI'),
ISPICKVAL(SBQQ__Quote__r.State_Province__c,'CO'),
ISPICKVAL(SBQQ__Quote__r.State_Province__c,'AZ'),
ISPICKVAL(SBQQ__Quote__r.State_Province__c,'UT')),
Dist_Test_Price__c < 16.50),
"Requires Exception",
"Pass")
AnkaiahAnkaiah (Salesforce Developers) 
Hi Chris,

Are you using all pickilist values in the formula or specific values ?

If you are checking specific picklist values then formula is good.
If you are using all pickist values then you can make the formula like below.
IF(
AND(
SBQQ__ProductCode__c = '734000',
NOT(ISBLANK(SBQQ__Quote__r.State_Province__c)),
Dist_Test_Price__c < 16.50),
"Requires Exception",
"Pass")

If this helps, Please mark it as best answer.

Thanks!!
 
Chris High 6Chris High 6
Just the specific states that I listed. I was just hoping my formula wasn't "good" because what a waste of character limit!
SteveMo__cSteveMo__c
I would use a CASE Function like this 
IF(
AND(
	SBQQ__ProductCode__c = '734000',
	CASE(SBQQ__Quote__r.State_Province__c,
	'TX'), 1,
	'NY'), 1,
	'VA'), 1,
	'NC'), 1,
	'KY'), 1,
	'AL'), 1,
	'NJ'), 1,
	'SC'), 1,
	'FL'), 1,
	'GA'), 1,
	'CA'), 1,
	'OK'), 1,
	'MI'), 1,
	'CO'), 1,
	'AZ'), 1,
	'UT'), 1,
	0 ) = 1,
	Dist_Test_Price__c < 16.50
),
'Requires Exception',
'Pass')