+ Start a Discussion
Money Care 7Money Care 7 


Hi All I am getting error when i am deleting the record like

Visualforce Error
Help for this Page
System.LimitException: Too many SOQL queries: 101
Error is in expression '{!deleteAll}' in component <apex:commandButton> in page dynamicsearch: Trigger.DuplicatePreventer: line 20, column 1
Trigger.DuplicatePreventer: line 20, column 1

trigger DuplicatePreventer on MasterTest__c (before insert, before update) {
        Map<String, MasterTest__c> cbkUserMap = new Map<String, MasterTest__c>();

        for (MasterTest__c cbkUser : System.Trigger.new) {

            if ((cbkUser.Name != null) && (System.Trigger.isInsert ||
 (cbkUser.Name != System.Trigger.oldMap.get(cbkUser.Id).Name))) {

                if (cbkUserMap.containsKey(cbkUser.Name)) {
                    cbkUser.Name.addError('Another new MasterTest__c has the same MASTER_CODE.');
                } else {
                    cbkUserMap.put(cbkUser.Name, cbkUser);

        for (MasterTest__c cbkUser :[SELECT Name FROM MasterTest__c WHERE Name IN :cbkUserMap.KeySet()]) {
           MasterTest__c newCbkUser = cbkUserMap.get(cbkUser.Name);
            newCbkUser.Name.addError('A MasterTest__c with this MATSER_CODE already exists.');

SandhyaSandhya (Salesforce Developers) 

You will get this error when you exceed the governor limits.

Please refer below link.

Hope this helps you!

Thanks and Regards
vinita kumari 8vinita kumari 8

It seems like your trigger does not have any issue, share the method "deleteAll" that you are calling from VF page.