Need help in writing logic for below requirement.
I have a custom object and a web service is enabled to insert data into it from external system. Inside the service we have a logic to validate if similar record is already existing (we use multiple parameters to compare), we have to merge the new record to existing. I was able to achieve it by querying the object before insertion.
But the problem I see is, as its a web service, external system is calling the web services in bulk at once. Thus, in some situations where similar records being called through service at same time, we are not getting records while querying to validate our conditions and duplicates are getting inserted to system.
Also, if there are any data related errors etc, I need to respond back in the web service.
Whats the best way / place to put these validations / the logic?