-2

I'm trying to create a formula that calls for picklist values if a field contains that data. Unfortunately I seem to have a syntax error. Can you take a look and tell me what is wrong?

IF(
    ISPICKVAL(central__c, 'APEX'),
    0Y209000000TcxiCAC
)
)
IF(
    ISPICKVAL(central__c, 'INDEPENDANT'),
    0Y209000000TcybCAC
)
),
NULL
)
)
3
  • Formatting the formula according to best practice makes the syntax errors clear (you have more than a few extra ), your id values are not enclosed in quotes, your IF() functions are missing their third parameter, you're missing a few commas), but it's not entirely clear what you intend for this formula to do. I'll give my best shot at an answer, but realize that the more details you include the more accurate the answers you'll tend to receive.
    – Derek F
    Commented Apr 5, 2023 at 16:29
  • Do you want This formula should return '0Y209000000TcxiCAC' if the picklist value in the field 'central__c' is 'APEX', '0Y209000000TcybCAC' if the picklist value is 'INDEPENDANT', and NULL if neither of these values are selected ? Commented Apr 5, 2023 at 16:35
  • N.B. Independant is misspelled - Independent is correct; if you have the chance to fix this before it gets into PROD, now's the time
    – cropredy
    Commented Apr 6, 2023 at 1:09

2 Answers 2

1

There's a time to use ISPICKVAL, and a time not to. This is one of those times when you shouldn't. CASE is easier to read and maintain, so it should be preferred in this case.

CASE(central__c, 
'APEX', '0Y209000000TcxiCAC',
'INDEPENDANT', '0Y209000000TcybCAC',
NULL
)

Note that your most likely syntax problem were the missing quotes around ID values. You must always enclose strings in quotes. The three main types of data that don't use quotes are numbers, Boolean values (true/false), and null.

1

I can't really tell what exactly you're trying to do here, but assuming that the formula would be semantically correct if the syntax errors were fixed... it'd look like this

IF(
    ISPICKVAL(central__c, 'APEX'),
    /* Strings need to be enclosed in quotes (either single or double quotes, not */
    /* "smart" quotes) */
    /* You also need a comma after each argument */
    '0Y209000000TcxiCAC',

    /* The way to do an if-else in a formula is to nest another IF() in the 3rd argument */
    IF(
        ISPICKVAL(central__c, 'INDEPENDANT'),
        '0Y209000000TcybCAC',
        /* IF() requires 3 arguments, no more, no less */
        null
    )
)

Note the placement and usage of closing parenthesis and commas. Close paren ends a function (or a logical grouping like 2 * (3 + 4) for specifying the order of evaluation). Commas are used between arguments to a function.

While that should be syntactically correct, that's a rather obtuse way to test a single field against multiple values. A better choice here would be the CASE() function.

CASE(
    /* The first argument is always the expression to match the values listed below against */
    /* CASE() is also one of the few things that can work on picklists directly */
    Central__c,

    /* Next up, value - result pairs */
    'APEX', '0Y209000000TcxiCAC',
    'INDEPENDANT', '0Y209000000TcybCAC',

    /* Finally, the result to yield if there are no value matches */
    null
)

I've included extra blank lines here in the hope that it makes things easier to read.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .