function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Giancarlo AmatiGiancarlo Amati 

Executing Apex Production generate 101 too SQL queries

Dear Team,
I need to trigger an APEX Trigger class only to a subset of Cases which oddly my APEX Batch class skipped. 
In my production environment, I have opened the Developer Console window --> Open Execute Anonymous Window and pasted the following code. By calling 'update cc' I will trigger the Case Trigger. However, I get the error in the snapshot.

My questions:
1) How can I run my apex batch class ONLY on the cases that were missed?
2) Is there a way to call the Apex instruction without generating the "Too Many SQL Queries" message?
Thank you.
GC
 
List<case> ccL = [SELECT CreatedDate, Met_SLA_2__c FROM Case WHERE ((CALENDAR_YEAR(CreatedDate) >= 2016) AND (Met_SLA_2__c = null) )];

System.debug('Size List: ' + ccl.size());

for (Case cc: ccL){
    update cc;
}


User-added image


 
GhanshyamChoudhariGhanshyamChoudhari
Which case field do you want to update? 
Giancarlo AmatiGiancarlo Amati
I want to call the 'update cc' on each case record as that will trigger the call of a Case Trigger. The case trigger then will automatically update MET_SLA__2 that is a field of the Case record. 

Thank you.
GhanshyamChoudhariGhanshyamChoudhari
List<case> ccL = 
[SELECT CreatedDate, Met_SLA_2__c FROM Case WHERE ((CALENDAR_YEAR(CreatedDate) >= 2016) AND (Met_SLA_2__c = null) )];
List<case> hold = new List<case>();
System.debug('Size List: ' + ccl.size());

for (Case cc: ccL){
cc.Met_SLA_2__c='your values';
hold.add(cc);
    
}
update hold;

 
Giancarlo AmatiGiancarlo Amati

Hi 
GhanshyamChoudhari, thank you but I don't see how that helps. Can you explain, please? In my production environment, I have a Case Trigger already working for new Cases. The value of Met__SLA__2__C is assigned from within the Case trigger.  I don't want to assign any value manually. Will 'your values' be overwritten by the Case Trigger?

Thank you.

G

Giancarlo AmatiGiancarlo Amati
I modified my code slightly in the hope to bulkify better but no improvement:
 
List<case> ccL = [SELECT CreatedDate, Met_SLA_2__c FROM Case WHERE ( (CreatedDate >= 2016-05-15T00:00:00Z) AND ((CreatedDate <= 2016-06-15T00:00:00Z)) AND (MET_SLA_2__c = null) )];

System.debug('Size List: ' + ccl.size());

update ccL;

 
Giancarlo AmatiGiancarlo Amati
`Decided to re run the apex batch.
Bye
GhanshyamChoudhariGhanshyamChoudhari
Open Execute Anonymous Window 
1 st run this code
List<case> ccL = 
[SELECT CreatedDate, Met_SLA_2__c FROM Case WHERE ((CALENDAR_YEAR(CreatedDate) >= 2016) AND (Met_SLA_2__c = null) )];
List<case> hold = new List<case>();
System.debug('Size List: ' + ccl.size());

for (Case cc: ccL){
cc.Met_SLA_2__c='XXXXX';
hold.add(cc);
    
}
update hold;

clear Execute Anonymous Window
then run 2nd code
List<case> ccL = 
[SELECT CreatedDate, Met_SLA_2__c FROM Case WHERE ((CALENDAR_YEAR(CreatedDate) >= 2016) AND (Met_SLA_2__c = 'XXXXX') )];
List<case> hold = new List<case>();
System.debug('Size List: ' + ccl.size());

for (Case cc: ccL){
cc.Met_SLA_2__c=null;
hold.add(cc);
    
}
update hold;