0

I am writing a formula that will execute a workflow action to change an ownership of an opportunity to the database. However, if the user making the change on the opportunity is one of three profiles and attempting to change the owner, I don't want to execute this action as it would switch back to database every time, so I am setting the formula explicitly to evaluate to false in this instance. I'm not very experienced in writing formulas and am getting the error in the title when I check my syntax. I matched up all of the parentheses in a code editor so I think I may be doing something else wrong. Here is my formula.

IF(
    $Profile.Name = 'Sales Manager' || $Profile.Name = 'Sales Operations || $Profile.Name = 'System Administrator' && ISCHANGED(OwnerId)
), false, (
    (
        CONTAINS(Account.Owner.UserRole.Name, 'Direct')
    ) && (
        Stage_Duration__c > 60
    ) && (
        StageName = 'New Opportunity'
    ) && (
        StageName <> 'Launched'
    ) && (
        StageName = 'Post Launched'
    ) && (
        StageName <> 'Lost'
    )
)
1

1 Answer 1

4

I think you have a couple things going on here.

  1. You're missing a closing quote after $Profile.Name = 'Sales Operations
  2. You have a parenthesis that's unneeded after ISCHANGED(OwnerId)
  3. You need an additional parenthesis at the end of the formula.
  4. While not technically an issue, you have extra parentheses around the CONTAINS() function (and elsewhere)

If you add some formatting, it can help make it more obvious where things have become misaligned:

IF(
  $Profile.Name = 'Sales Manager' 
  || $Profile.Name = 'Sales Operations' 
  || $Profile.Name = 'System Administrator' 
  && ISCHANGED(OwnerId), 
  false, 
  (
    CONTAINS(Account.Owner.UserRole.Name, 'Direct')
    && Stage_Duration__c > 60
    && StageName = 'New Opportunity'
    && StageName <> 'Launched'
    && StageName = 'Post Launched'
    && StageName <> 'Lost'
  )
)
5
  • Yeah that formatting makes it much easier to spot. Thanks! I'm used to working in an IDE and formatting sort of being done for me so I appreciate the example.
    – Josh
    Commented Feb 1, 2019 at 23:05
  • +1 for the advice for formatting. Newlines and indentation are a very powerful tool for debugging (and not just for formulae, sensible formatting also helps in debugging/digesting Apex, Lightning/Javascript, and Visualforce)
    – Derek F
    Commented Feb 1, 2019 at 23:05
  • You could get rid of quite a few parentheses still, which would probably reduce the risk of this type of mistake. Still, hadn't seen you on here in a while. Nice to see you back after a long hiatus. :)
    – Adrian Larson
    Commented Feb 1, 2019 at 23:21
  • Good catch @AdrianLarson - I updated the answer accordingly. I'm baaaaack! Commented Feb 3, 2019 at 1:10
  • One thing I just noticed, the conditions AND join two separate equality checks on StageName. They cannot possibly both be true concurrently.
    – Adrian Larson
    Commented Feb 3, 2019 at 1:13

You must log in to answer this question.

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