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
Michael_TorchedloMichael_Torchedlo 

Long Text Area Field - Unique?

Does anyone have a way to make a Long Text Area or Rich Text Area field unique?  We have a custom field on a custom object that is slightly longer than a regular text field but I still want to block duplicates.
Best Answer chosen by Michael_Torchedlo
Tolga SunarTolga Sunar
Just tested on my dev org, and these two text field types do not show up in Matching Rule criteria.

A possible solution may be preparing a before insert & before update trigger, which copies the long/rich text area value to a background text field you're going to create. This trigger will do the update and trigger the uniqueness criteria of background text field. However, you will need to use only up to the first (or last) 255 characters of your long/rich text area field.

This link may be helpful on this subject: https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_triggers_order_of_execution.htm

All Answers

Tolga SunarTolga Sunar
Just tested on my dev org, and these two text field types do not show up in Matching Rule criteria.

A possible solution may be preparing a before insert & before update trigger, which copies the long/rich text area value to a background text field you're going to create. This trigger will do the update and trigger the uniqueness criteria of background text field. However, you will need to use only up to the first (or last) 255 characters of your long/rich text area field.

This link may be helpful on this subject: https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_triggers_order_of_execution.htm
This was selected as the best answer
Michael_TorchedloMichael_Torchedlo
Thanks Tolga.  I suppose if my data set were small enough, I could use an Apex trigger and class to check uniqueness.  It appears to be the only option for these field types now, unfortunately.