You need to sign in to do that
Don't have an account?

Need to find duplicate records using firstname, last name and date of birth
I am inserting records in a custom object name as RAW patient order through data loader and i have written a trigger which picks some values from this object and insert into patient and patient order objects.
We have to do one more additional check here for the patients. Customer
mentioned that they will get the orders from the same patient
over and over. In that scenario we should not be creating duplicate patients.
We have to check for the following patient and see if it
exists. If so, skip the creation process and just create patient
orders alone by associating with the existing patients.
Unique Identifier for Patient: first name,
last name and birth date
Now I am facing the problem that how would i check this condition from the database. if i go for soql query one by one for every inserting record than surly i will face soql execution limits.
Please suggest, if any one have any idea to achieve this functionality
Thanks in advance!!
SYM12,
There are various ways you can achieve this, the most common is to query the Patients once in your code and then looking if they exist in the collection.
I would suggest creating a map<String,Patient> , having String be the unique key (firstname+lastname+birth) , since they can all be represneted as a string, then just do:
private patient createPatient ( patientInfo ) {
...
String uniqueKey = firstName+lastName+birth;
if( !myPatientsMap.containsKey(uniqueKey) ) {
// create
insert newPatient;
return newPatient
}
else {
// do whatever is needed, most likely return existing user
return myPatientsMap.get(uniqueKey);
}
}
This would effectively prevent you from creating existing patients ,and only querying once in your code.
Be careful with governor limits!. If you fear the results will exceed GovLimits, try filtering the query by matching lastnames with the ones you are trying to create, or some other field.
This is just a suggestion on how to, not exactly working code.
Let me know if this helped you,
Gaston.