-
Why is Trigger Not Working For Bulk Insert?
I have created a trigger On Contact.
My requirement is to check the given conditions before insert / before update and throw error when the conditions are true.
- Duplicate Email is not allowed.
- Contact cannot be Type 4.The Trigger is Working fine when I am inserting contact manually but it is not Working for Bulk insert. It is accepting Duplicate Email values for Bulk insert. Can anybody suggest me how to achieve that?
Trigger Code---
trigger checkEmail on Contact (before insert,after insert,before update) { List conList = [select Email,Type__c from contact]; for(Contact conToInsert : Trigger.New){ for(Contact conToCompare : conList){ if(conToInsert.Type__c == 'Type 4' ){ conToInsert.addError('Contact Cannot be Type 4'); } else{ if(conToInsert.Email != null){ if(conToInsert.Email == conToCompare.Email){ conToInsert.addError('Same Email Found Cannot Insert'); } } } } } }
- This discussion was modified 8 years, 8 months ago by Shubham.
- This discussion was modified 8 years, 4 months ago by Forcetalks.
Log In to reply.
Popular Salesforce Blogs
Salesforce Has Acquired Phennecs, A Well-Known Provider of Privacy, Compliance, and Data Management Solutions
After enjoying being in the years-long OEM (Original Equipment Manufacturer) partnership, World’s number one CRM solution provider, Salesforce, has completed the acquisition of Phennecs, the…
How Salesforce Einstein Works for FinTech: Features & Benefits Overview
67% of respondents consider artificial intelligence to be a top technology that will influence fintech over the decade. At the forefront of fintech's dynamic progress, Salesforce…
Salesforce Security Mastery: Object, Permission Sets, Field, and Record-Level Strategies with OWD
What You’ll Learn: How to protect an Object in Salesforce Security? What is Profile Level Security? What is Permission Set in Salesforce? Difference between Profile…