-
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 10 years, 5 months ago by
Shubham.
-
This discussion was modified 10 years, 1 month ago by
Forcetalks.
-
This discussion was modified 10 years, 5 months ago by
Log In to reply.
Popular Salesforce Blogs
Don't Miss to Check Out The Top Salesforce Trends In 2022
Salesforce is taking its strength in cloud computing to a new level. It gained market share by making an easy to use and affordable software…
How to schedule the batch class at specific time ?
To invoke the Apex batch classes to run at specific times, first we need to implement the Schedulable interface for the Apex class, then specify…
Salesforce Governor Limits
Before starting to know all the rules(which we are always so excited to follow.Not!). We need to know why we need all these rules(which Salesforce…