+ Start a Discussion
bkradminbkradmin 

Problem with Syntax

Hi, I am very new to formulas and SF and can't seem to get SF syntac right. I keep getting errors on this formula. I would really appreciate some help! 

 

If ((RecordType.Id), ("012E0000000MoYF") || ( RecordType.Id), ("012E0000000Mu8O") || ( RecordType.Id), ("012E0000000MoYN") || ( RecordType.Id), ("012E0000000MoYQ")),
( IF(ISPICKVAL(npe01__PreferredPhone__c, "Home"), HomePhone,
IF(ISPICKVAL(npe01__PreferredPhone__c, "Other"), OtherPhone,
IF(ISPICKVAL(npe01__PreferredPhone__c, "Work"), npe01__WorkPhone__c,
IF(ISPICKVAL(npe01__PreferredPhone__c, "Mobile"), MobilePhone, Account.Phone
),
( IF(ISPICKVAL(npe01__PreferredPhone__c, "Home"), HomePhone,
IF(ISPICKVAL(npe01__PreferredPhone__c, "Other"), OtherPhone,
IF(ISPICKVAL(npe01__PreferredPhone__c, "Work"), npe01__WorkPhone__c,
IF(ISPICKVAL(npe01__PreferredPhone__c, "Mobile"), MobilePhone, Employer_Number__c
)

Best Answer chosen by Admin (Salesforce Developers) 
Shannon HaleShannon Hale

Let me see if I can restate the requirements:

  1. If "Preferred Phone" is Home, Other, Work or Mobile, then return Home Phone, Other Phone, Work Phone or Mobile Phone, respectively.
  2. If it's anything else, then depending on what record type the record is, return Account.Phone or Employer_Number__c.

If this is correct, I think you can simplify this quite a bit like this:

 

CASE(
  npe01__PreferredPhone__c,
  "Home", HomePhone,
  "Other", OtherPhone,
  "Work", npe01__WorkPhone__c,
  "Mobile", MobilePhone,
  IF(
    (RecordTypeId = "012E0000000MoYF" || RecordTypeId = "012E0000000Mu8O" || RecordTypeId = "012E0000000MoYN" || RecordTypeId = "012E0000000MoYQ"),
    Account.Phone,
    Employer_Number__c
  )
)

How it works:

  1. Check the value of the npe01__PreferredPhone__c.
  2. If the value of npe01__PreferredPhone__c is Home, Other, Work or Mobile, return the appropriate phone field (it doesn't matter what the record type is).
  3. If the value of npe01__PreferredPhone__c is something else, then check the record type.
  4. If the record type ID is one of the four specified (and I switched it to use the RecordTypeId field instead of RecordType.Id, as it does not require a cross-object reference to use RecordTypeId), then return Account.Phone.
  5. If the record type isn't one of the four specified, return Employer_Number__c.

 

If I got the requirements wrong there, please explain further what you're trying to do and we'll see if we can help you out.

All Answers

Avidev9Avidev9
May be the first line is causing trouble.
If ((RecordType.Id), ("012E0000000MoYF") || ( RecordType.Id), ("012E0000000Mu8O") || ( RecordType.Id), ("012E0000000MoYN") || ( RecordType.Id), ("012E0000000MoYQ"))

You never compared values.

Proper syntax would be
IF(RecordType.Id == '012E0000000MoYF','return value1','return value2')
KT1KT1

Also, are all of those IF statements "AND's or OR'S".

 

We need more information to figure out how it should be.

Shannon HaleShannon Hale

Let me see if I can restate the requirements:

  1. If "Preferred Phone" is Home, Other, Work or Mobile, then return Home Phone, Other Phone, Work Phone or Mobile Phone, respectively.
  2. If it's anything else, then depending on what record type the record is, return Account.Phone or Employer_Number__c.

If this is correct, I think you can simplify this quite a bit like this:

 

CASE(
  npe01__PreferredPhone__c,
  "Home", HomePhone,
  "Other", OtherPhone,
  "Work", npe01__WorkPhone__c,
  "Mobile", MobilePhone,
  IF(
    (RecordTypeId = "012E0000000MoYF" || RecordTypeId = "012E0000000Mu8O" || RecordTypeId = "012E0000000MoYN" || RecordTypeId = "012E0000000MoYQ"),
    Account.Phone,
    Employer_Number__c
  )
)

How it works:

  1. Check the value of the npe01__PreferredPhone__c.
  2. If the value of npe01__PreferredPhone__c is Home, Other, Work or Mobile, return the appropriate phone field (it doesn't matter what the record type is).
  3. If the value of npe01__PreferredPhone__c is something else, then check the record type.
  4. If the record type ID is one of the four specified (and I switched it to use the RecordTypeId field instead of RecordType.Id, as it does not require a cross-object reference to use RecordTypeId), then return Account.Phone.
  5. If the record type isn't one of the four specified, return Employer_Number__c.

 

If I got the requirements wrong there, please explain further what you're trying to do and we'll see if we can help you out.

This was selected as the best answer
bkradminbkradmin

You are a genius. This is exactly what I was trying to do. Works like a charm. Bless you.