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
http://help.skuidify.com/m/11720/l/205332-skuid-ui-editor
Regards,
Irvin
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> message:'Assigning...',<br> 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> var recs = result.records;<br> if(recs){//we got something back from the query! so let's not save...<br> alert('The record you are trying to add already exists!');<br> return;<br> }<br> else{//just save and everything is groovy :)<br> model.save();<br> }<br>});
Much better that JavaScript/CSS monkey tricks. Nice one Moshe.
Enter your E-mail address. We'll send you an e-mail with instructions to reset your password.