salesforceformulasalesforce-lightningsalesforce-communities

Validation Formula throws an Invalid Syntax Error - Salesforce


I am trying to create a validation formula in order to perform the below logic.

These field values cannot be duplicated in the database. Therefore every new entry to be inserted needs to be validated accordingly.

For this, I am using the below formula

NOT(EXISTS((SELECT Id  FROM I_Coverage__c  
 WHERE I_Priority__c = {{I_Priority__c}}
   AND C_Start_Date__c = {{C_Start_Date__c}}
   AND C_End_Date__c = {{C_End_Date__c}})))

When I press the 'Check Syntax' button, I am getting

Error: Syntax error. Missing ')'

Error


Solution

  • This is... very misguided. You can't run queries in formulas like that and where's that {{syntax}} coming from. Are you a Marketing Cloud person or something?

    I'll list some options but you have lots of reading to do.


    So... is there an easy config solution? Yep.

    1. Create a helper text field, Unique__c Text, 255. Mark it Unique case insensitive.
    2. Create an "early flow" or before insert, before update trigger if you feel like it, populating the field with combination of your 3 fields. No conditions, can run always (low performance impact and before means it's a save for free).
    3. Run a data fix that mass updates your records (if you did #2 you can just "touch" them, update without changing anything, should populate.
    4. Try to break it.