-
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 9 years, 10 months ago by
Shubham.
-
This discussion was modified 9 years, 6 months ago by
Forcetalks.
-
This discussion was modified 9 years, 10 months ago by
Log In to reply.
Popular Salesforce Blogs
How to Select a Certified Salesforce Consultant?
Cloud computing was always there in one form or another, but it has started to really develop in the past half-decade or so. Salesforce is…
No Code Salesforce and Outlook Integration
Microsoft Outlook is a personally identifiable information management software system included in the Microsoft Office suite. Outlook is essentially an email client, and also contains…
Configure Salesforce SAML Single Sign-On in 2024
Configuring Salesforce SAML Single Sign-On (SSO) is a critical step in enhancing both the security and user experience within your organization. SAML (Security Assertion Markup…