-
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, 7 months ago by Shubham.
- This discussion was modified 8 years, 3 months ago by Forcetalks.
Log In to reply.
Popular Salesforce Blogs
Omni-сhannel in Salesforce: Setting the Standard for Customer Service
Modern consumers demand convenience, connecting with companies from anywhere using smartphones or laptops. The true advantage emerges when customers have multiple options tailored to their…
Einstein Application and Licenses in Salesforce Sales Cloud in 2024
Einstein Lead Scoring Use AI to score your leads by how well they fit your company’s successful conversion patterns. Let your sales team prioritize their…
What are the Benefits of Integrating Salesforce Order Management System with e-commerce in 2023?
The e-commerce industry has evolved from small stores to megastores in the passing years. However, managing the back end of an online retail business is…