Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- The following Trigger will fires when we try to create the account with same name i.e Preventing the users to create Duplicate Accounts.
- Trigger duplicateAccTrigger on Account (Before Insert){
- switch on Trigger.operationType {
- when BEFORE_INSERT {
- duplicateAccHelper.checkDuplicateAcc(Trigger.new);
- }
- }
- }
- Public with sharing duplicateAccHelper {
- public static void checkDuplicateAcc(List<account> accLst){
- if(accLst != null || accLst.size() > 0){
- for(Account acc : accLst){
- List<Account> accCheck = [SELECT Id, name from account where name = acc.name AND rating= acc.rating];
- if(accCheck.size() > 0 ){
- acc.name.addError = 'Account is already been created';
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement