Contents
How to prevent duplicate contact in Salesforce apex?
Populate the above List with of existing records whose email id or phone number matches the ones being created. Iterate through each record being created and display and error if the record already exists. Now lets go through each step once again and write its respective code.
When to throw a trigger in Salesforce apex?
When a Contact is being created, if a record with the same Email or Phone number exists, the trigger should throw an error and the user should not be allowed to create the duplicate Contact. To achieve this, we will write a trigger with the following flow:
How to store email ids in Salesforce apex?
Create Sets to store the ‘Email Ids’ and ‘Phone Numbers’ of all the records that are being created Iterate through each record that is being created, and add their ‘Email Ids’ and ‘Phone Numbers’ to the Sets. Create a List to store the ‘Email Ids’ and ‘Phone Numbers’ of existing records that match the records being created.
What does it mean to bulkify Apex code?
Bulkifying Apex code refers to the concept of making sure the code properly handles more than one record at a time. An individual Apex request gets a maximum of 100 SOQL queries before exceeding that governor limit. So if this trigger is invoked by a batch of more than 100 Account records, the governor limit will throw a runtime exception
How to check duplicate email in the trigger while insert and update?
It will help other to find best answer. I used your code, but found a bug while finding duplicates record on base of Email in the imported batch, i.e. If imported batch have duplicate email itself it doesn’t handle that. I tried suresh code it is working fine i used data import wizard for loading and it is working fine
Why is MySQL giving me a duplicate entry error?
Switching to “bigint” fixed the problem. As per your code your “number” and “Name” are primarykey and you are inserting S.NAME in both row so it will make a conflict. we are using primarykey for accessing complete data. here you cant access the data using the primarykey ‘name’. im a beginner and i think it might be the error.
Is there a duplicate key entry error in DML?
When the DML operations are applied, it is possible to encounter a duplicate key entry error (ERROR 1062 (23000): Duplicate entry), even if the duplicate entry is only temporary and would be reverted by a later entry in the “online log”.