How to prevent duplicate value errors to be displayed?

We have a unique field to prevent duplicate entries from being inserted. We delegated this to Salesforce to minimize the number of server calls.
The problem is that even though we anticipate that exception can occur, we are unable to find a way to prevent the duplicate values errors from being shown.

Please advice.

Hi Rodrigo,

I had a chat with Pat Vachon about this issue and he suggested CSS could help here.  

Following Pat’s train of thought, messages are displayed in a .nx-message DOM node and added to a .nx-messages DOM container.  So you could hide the container until the save returns, inspect the messages & remove the dup value messages, then unhide the container.  Seems sort of hackish but could work if there it is no better way.

Check out this tutorial for more details


If you want to get a little crazy, you can try something like this. I ran into a very similar issue and here’s my hackish approach. I’m assuming you have a unique id based on 2 or more fields concatenated together. Let’s say “opportunityId + accountId” is the key. In that case you can query salesforce before the save, and check if a record with that unique key already exists, based on the values the user has entered. This may seem cumbersome but actually runs pretty fast. You can use the snippet below, just replace all of the API names with your field names.

var params = arguments[0], $ = skuid.$;<br>$.blockUI({<br>&nbsp; &nbsp; message:'Assigning...',<br>&nbsp; &nbsp; timeout: 1500<br>});<br>//variable declarations to get at model, row and fields<br>var MODEL_NAME = 'Your Model Name';<br>var model = skuid.$M(MODEL_NAME);<br>var row = model.getFirstRow();<br>var field1 = row.Your_Field__c;<br>var field2 = row.Your_Other_Field__c<br>//setup the unique string manually<br>var str = field1.toString() + field2.toString();<br>//check if these combinations exist<br>var qryStr = "Select Id, Unique_Id__c From You_Object__c Where Unique_Id__c = '" + str + "'";<br>var result;<br>//use the AJAX API to query salesforce and see if this combination already exists before the save<br>$.when(result = sforce.connection.query(qryStr)).done(function(){<br>&nbsp; &nbsp; var recs = result.records;<br>&nbsp; &nbsp; if(recs){//we got something back from the query! so let's not save...<br>&nbsp; &nbsp; &nbsp; &nbsp; alert('The record you are trying to add already exists!');<br>&nbsp; &nbsp; &nbsp; &nbsp; return;<br>&nbsp; &nbsp; }<br>&nbsp; &nbsp; else{//just save and everything is groovy :)<br>&nbsp; &nbsp; &nbsp; &nbsp;;<br>&nbsp; &nbsp; }<br>});

Much better that JavaScript/CSS monkey tricks.  Nice one Moshe.