You need to sign in to do that
Don't have an account?
Mike Cerruti
System.Limit Exception: Too many SOQL queries: 101
I'm trying to create a class and method that will update a field on a record when a picklist value is changed. I get the Too many SOQL queries error.
It is called by the following trigger:
trigger triggerUpdateTravelChange on Travel_Detail__c (after update, before update) {
Travel_Detail__c[] travel_details = Trigger.new;
If(Trigger.Isafter){
//Updates the Change Travel Ticket Date and
//Increments the Change Travel Ticket Revision
//on the Travel Ticket
UpdateTravelChange.findTravelDetail(travel_details);
updateTravelDetailStatus.updateTravelTicket(travel_details);
//TravelCalendarUpdate.TravelDetail(travel_details);
}
If(Trigger.Isbefore){
//Updates the Change Revision and Change Date Fields
// on the Travel Detail Record
TravelDetailBooked.updateBooked(travel_details);
}
}
Apex Class
trigger triggerUpdateTravelChange on Travel_Detail__c (after update, before update) {
Travel_Detail__c[] travel_details = Trigger.new;
If(Trigger.Isafter){
//Updates the Change Travel Ticket Date and
//Increments the Change Travel Ticket Revision
//on the Travel Ticket
UpdateTravelChange.findTravelDetail(travel_details);
updateTravelDetailStatus.updateTravelTicket(travel_details);
//TravelCalendarUpdate.TravelDetail(travel_details);
}
If(Trigger.Isbefore){
//Updates the Change Revision and Change Date Fields
// on the Travel Detail Record
TravelDetailBooked.updateBooked(travel_details);
}
}
It is called by the following trigger:
trigger triggerUpdateTravelChange on Travel_Detail__c (after update, before update) {
Travel_Detail__c[] travel_details = Trigger.new;
If(Trigger.Isafter){
//Updates the Change Travel Ticket Date and
//Increments the Change Travel Ticket Revision
//on the Travel Ticket
UpdateTravelChange.findTravelDetail(travel_details);
updateTravelDetailStatus.updateTravelTicket(travel_details);
//TravelCalendarUpdate.TravelDetail(travel_details);
}
If(Trigger.Isbefore){
//Updates the Change Revision and Change Date Fields
// on the Travel Detail Record
TravelDetailBooked.updateBooked(travel_details);
}
}
Apex Class
trigger triggerUpdateTravelChange on Travel_Detail__c (after update, before update) {
Travel_Detail__c[] travel_details = Trigger.new;
If(Trigger.Isafter){
//Updates the Change Travel Ticket Date and
//Increments the Change Travel Ticket Revision
//on the Travel Ticket
UpdateTravelChange.findTravelDetail(travel_details);
updateTravelDetailStatus.updateTravelTicket(travel_details);
//TravelCalendarUpdate.TravelDetail(travel_details);
}
If(Trigger.Isbefore){
//Updates the Change Revision and Change Date Fields
// on the Travel Detail Record
TravelDetailBooked.updateBooked(travel_details);
}
}
It is for sure that trigger fall under recursion so try to create debug log and check how may times your trigger is executing .
Below is the link for sample code to control recursion ,Implement that your problem will resolve .
https://help.salesforce.com/apex/HTViewSolution?id=000133752&language=en_US (https://help.salesforce.com/apex/HTViewSolution?id=000133752&language=en_US)
Thnaks
Manoj
All Answers
Also, it's generally good practice for the trigger to do nothing more than just call an Apex class that actually does all of the work. That's not required but makes you're system easier to troubleshoot.
The class is:
public class updateTravelDetailStatus {
public static void updateTravelTicket(Travel_Detail__c[] travel_details){
Integer i = 0;
Integer c = 0;
List<Travel_Detail__c> travel_detail = new List<Travel_Detail__c>{};
travel_detail = [Select Name
From Travel_Detail__c
Where detail_status__c = 'Cancel'
Order by Name ];
For (Travel_Detail__c td :travel_detail){
System.debug('Name: ' + td.Name + ' No: ' + i); i++;
} // End List
List<Travel_Detail__c> detailToUpdate = new List<Travel_Detail__c>(); {
For(Travel_Detail__c td :travel_detail){
td.Change_Notes__c = 'Updated by Apex';
detailToUpdate.add(td);
System.debug('Name: ' + td.Name + ' Notes: ' + td.Change_Notes__c);
} // End For
} // End List
update detailToUpdate;
} // End Method
} // End Class
Please check if any Workflow rules defined on object "Travel_Detail__c", If so please deactivate and try to execute the trigger context. If you still see the same problem, check your trigger is calling recurssively. My strong feeling is trigger is being excuted recurssively. Please use static boolean to control the recurrsive execution of trigger. This will solves your problem.
Please mark solved/best answer. if this helps for you.
It is for sure that trigger fall under recursion so try to create debug log and check how may times your trigger is executing .
Below is the link for sample code to control recursion ,Implement that your problem will resolve .
https://help.salesforce.com/apex/HTViewSolution?id=000133752&language=en_US (https://help.salesforce.com/apex/HTViewSolution?id=000133752&language=en_US)
Thnaks
Manoj