How to avoid duplicated records

Posted by caylali on 09-Feb-2016 00:14


Object A has a trigger: when the status field changed to "1", create a record in Object B.

When the status field of A changed back to "0", there is no trigger, we want keep the record in B.

However, when we change the status of A to "1" again, the trigger will create another record in B, which is duplicated.

Is there an option to check whether the record is exist in B before the trigger is triggered?? Thanks.

All Replies

Posted by Mani Kumar on 09-Feb-2016 05:45

Hi Cayla,

I understand that you might be using "Create New Record" trigger on the related objects.In that respect is no out of the box way to perform this in your use case.

 You can try below options:

 1. Include Trigger script to validate the existing records before creating.


 2. Include a field level validation NOT to allow duplicates.


Please correct me if my understanding is not correct.



Posted by Shiva Duriseati on 09-Feb-2016 05:51

Hi Caylali,

As Mani mentioned in the earlier post, you can restrict , creation of duplicate records by checking the value "Do not allow duplicate values" in the field of object definition.

I have created two workflow status "0" and "1" , created " status change workflow action" by selecting a trigger of type "object script".

Attaching app.xml for your reference. Please let me know if you need any assistance.[View:/cfs-file/__key/communityserver-discussions-components-files/25/SampleApp_5F00_v2.xml:320:240]

Posted by caylali on 09-Feb-2016 17:48

Thanks Mani and Shiva. I tried to check he value"Do not allow duplicated values" for Object B, and then change the status of Object A, it returns an error, and wont allow me to change the status.

"Error executing Trigger: "CreateRecordInB" Error ObjectB "somevalue" is already in use. "

I will try to write the script to search in Object B and then decide whether to create record in Object B or update the current record or do nothing. If there is existing code sample for this function, please let me know. Thanks.

Posted by Siddeshwar on 10-Feb-2016 00:10

Hi caylali,

Here is sample code, I tried to get record count for field 'myfield' having value 'myvalue', Edit below query with respective tokens for your object.

var count=rbv_api.selectQuery("SELECT count(*) FROM secondobj where myfield='myvalue'", 1);



//skip , record already exists




//create record




Posted by caylali on 11-Feb-2016 00:41

Hi Siddeshwar,

Thanks for your response. I have set up a trigger to create a merchant record when the merchant name is not exist yet. I used your code ,but it always returns false no matter whether "x" is in "Merchant" or not.

var count=rbv_api.selectQuery("SELECT count(*) FROM Merchant where name='x'", 1);


 return false;



 return true;

Posted by Siddeshwar on 11-Feb-2016 01:27

Hi caylali,

The above code is working fine for me.

Can you check the integration name for Object is 'Merchant' and field integration name is 'name' for the field that you want check condition.



This thread is closed