I want to add a field "Single Line of Text" to my custom entity which should be unique. How can I make Crm to throw me an exception when I try to create the duplicating value of the record?
You have to create a plugin for this requirement which handles the Pre-Create/Pre-Update step for this entity. In this plugin you have to check whether the passed value is unique or not. If it's not, you throw an exception which cancels the operation and displays a dialog to the user (if the plugin runs synchronously).
throw new InvalidPluginExecutionException("Value passed for 'attribute' is not unique.");
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With