You need to sign in to do that
Don't have an account?
ShadowlessKick
System.LimitException: Too many SOQL queries: 101
Trying to rewrite a trigger that keeps getting System.LimitException: Too many SOQL queries: 101. Thought it was in bulk structure but I guess not. The only reason there is a group by on the query was to try to limit the amount of data being returned. That did not help.
trigger CheckDuplicateContractNumber on Apttus__APTS_Agreement__c (before update) { List<Id> TheContractIds = new List<Id>(Trigger.newMap.keySet()); Integer theCountFound; for (Apttus__APTS_Agreement__c theAgreement :Trigger.new ) { for(AggregateResult ar : [SELECT Count(Id) thecounter, APTPS_BPCS_Contract_Number__c BPCSCntr from Apttus__APTS_Agreement__c WHERE APTPS_BPCS_Contract_Number__c = :theAgreement.APTPS_BPCS_Contract_Number__c AND Id Not IN :TheContractIds Group BY APTPS_BPCS_Contract_Number__c Limit 2]) theCountFound = Integer.valueOf(ar.get('thecounter')); if (theCountFound >= 1) { theAgreement.addError('The Contract Number already exists. Please enter a unique number.'); } } }
Although... why didn't you just use a unique index?
All Answers
Although... why didn't you just use a unique index?
You are an EXCELLENT contributor! Thank you!
You asked why I did not just use a "Unique Index." Could you expand on that idea? I am self-taught and any insight on new concepts are always appreciated.