-
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, 11 months ago by
Shubham.
-
This discussion was modified 8 years, 7 months ago by
Forcetalks.
-
This discussion was modified 8 years, 11 months ago by
Log In to reply.
Popular Salesforce Blogs

This Week’s Top Stories: Salesforce Updates Sales Cloud Features
Salesforce has recently announced a slew of new Sales Cloud features that aim to simplify administrative tasks for sales reps. According to a Salesforce report,…

Boost Your Sales with Effective Email Pitch Strategies in Salesforce
Clear communication with prospects is the key to building relationships and increasing sales, especially for B2B businesses. As B2B sales involve higher transaction value and…

An Introduction to Salesforce Force.com Migration Tool (ANT)
Let’s understand Metadata as: Data which give information about other Data. Metadata sums up essential data about information, making discovering, and working with specific examples…