0

How can i check for duplicate values while inserting data in salesforce using Visualforce Remote Objects. Here is my code:

 //Get form values.
     var woDetails = {
        Case__c: $scope.caseId,
        Name: $scope.Name,
        Priority__c: $scope.setPriority.priorityText,
        Status__c: $scope.Status,
        Description__c: $scope.Description,
        City__c: $scope.City,
        Street__c: $scope.Street,
        Zip__c: $scope.ZipCode
 };

  //Create work order
  var createWO = new WorkOrderModels.wo();
  //Insert work order details in work order object.
  createWO.create(woDetails, function(err) {
  if (err) {
    //Error message.
    msgBoxObj.showMessage(new messageBox().messageType.Error, err.message);
  } else {

    //Success message of Insert.
    msgBoxObj.showMessage(new messageBox().messageType.Success, "Work Order Saved Successfully!!");
    //Redirection.
     $window.location.href = "https://" + $window.location.host +"/apex/WorkOrderVF?" + "RecordId=" + $scope.caseId + "#/getWorkOrder";
     }
  });
1
  • why VF remoting? It should be done using Validation rule or trigger . Commented Feb 22, 2016 at 15:22

1 Answer 1

0

You can only enforce restrictions on object level in settings->create->object->your object->select field->mark as unique

2
  • Is there a way to do it from server side code. So that i can popup a message to the user saying that a record with such name already exists while the user is trying to insert it from a form. Commented Feb 22, 2016 at 18:08
  • Yes you can add apex:messages tag on VF page and mark some fields as unique and add validation rules to object. Commented Feb 22, 2016 at 21:22

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.