function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Maxi SMaxi S 

How can I prevent user from entering duplicate case insensitive sentences via apex?

How can I handle below validation scenario via Apex code?
Scenario: I have defined two text area fields in my object and want user to prevent from entering duplicate sentences (For case - Insensitivity)
Example: 
Text area 1: My name is Maxi. 
Text Area 2: mY naMe Is maXi.

Result: It should throw an error.
Can someone please help here.
Thanks in advance.
KaranrajKaranraj
Maxi - You can do that using validation rule.Try create validation rule on case object as mentioned below
CONTAINS( Lower(TextAreadField_1),  Lower(TextAreadField_2)) //replace with the API of the field

 
Maxi SMaxi S
Thanks Karanraj.

In my scenario, It could be more than two textareas. (Depends on user).
Is that case, how can I handle it?

 
KaranrajKaranraj
Maxi - You can use If condition and identify the user and profile details using $User.Name and $Profile.Name and you can form your contains logic more that one inputTextArea field. For example
IF( $User.FirstName  == 'Karanraj', //Condition
CONTAINS( TextAreadField_1,  TextAreadField_2), //If the condition is true
AND(CONTAINS( TextAreadField_1, TextAreadField_3),CONTAINS( TextAreadField_1,TextAreadField_4)) //Else condt.
)
In the else condition, TextAreadField_1 will be checked with ​TextAreadField_3 and ​TextAreadField_4. So with the help of AND /OR function you can able to check more than one field in your condition based on the user profile