+ Start a Discussion
Money Care 7Money Care 7 

Error!!!

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) 
Hi,

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

Please refer below link.

https://help.salesforce.com/apex/HTViewSolution?id=000181404&language=en_US
   
Hope this helps you!

Thanks and Regards
Sandhya
vinita kumari 8vinita kumari 8
Hi,

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