Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
794 views
in Technique[技术] by (71.8m points)

salesforce - Field formula with Case/If statement

I want to set a formula for a field C by check two picklist fields A and B (the value in the picklist will Yes, No, None)

 If field A = "Yes" and field B = "Yes"  then field C = "1"
 If field A = "Yes" and field B <> "Yes"  then field C = "2"
 If field A <> "Yes" and field B = "Yes"  then field C = "3"
 If field A <> "Yes" and field B <> "Yes"  then field C = "4"

I don't know how to set a formula for field C to make it works, I try CASE, IF statement without any luck.

Any help will be appreciated.

Thanks,

question from:https://stackoverflow.com/questions/65838553/field-formula-with-case-if-statement

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

I would suggest to spend some times on these trailhead: Use Formula Fields and Advanced Formulas.
Bookmarking Formula Operators and Functions documentation page would be useful too.

Since A and B are picklist fields you must use ISPICKVAL(field, value).
If C is a text formula field:

IF( ISPICKVAL(A, 'Yes'),
    IF ( ISPICKVAL(B, 'Yes'),
        '1',
        '2'
    ),
    IF ( ISPICKVAL(B, 'Yes'),
        '3',
        '4'
    )
)

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...