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
Gerald HarmensGerald Harmens 

Too many SOQL queries: 101 Error

Hello,

We are getting this error:
i360:Too many SOQL queries: 101 Error is in expression '{!Save}' in page i360:quickaction: (i360)    An unexpected error has occurred. Your solution provider has been notified. (i360)

From what we believe is the code below. Can you help us "clean up" the code and also let us know how to find the culprit of the error.
trigger Appointment_Price_Quoted on i360__Appointment__c (after update) 
{
    if(Trigger.isAfter)
    {
        if(Trigger.isupdate)
        {
            set<Id> ProspectSet = new set<Id>();
            for(i360__Appointment__c Appointment :Trigger.new){
                ProspectSet.add(Appointment.i360__Prospect__c);
            }
            map<string, i360__Prospect__c> ProspectMap = new map<string, i360__Prospect__c>(
               [SELECT Id, Appointment_Quoted_Price__c 
               FROM i360__Prospect__c
                WHERE Id IN :ProspectSet]
            );
            list<i360__Prospect__c> ProspectsToUpdate = new list<i360__Prospect__c>();
            for(i360__Appointment__c Appointment : Trigger.new){
                i360__Prospect__c prospect = new i360__Prospect__c();
                Prospect.Id = ProspectMap.get(Appointment.i360__Prospect__c).Id;
                if(Appointment.i360__Quoted_Amount__c != NULL && Appointment.i360__Prospect__c != null){
                    prospect.Appointment_Quoted_Price__c = Appointment.i360__Quoted_Amount__c;
                }else{
                    prospect.Appointment_Quoted_Price__c = 0.00;
                }
                ProspectsToUpdate.add(prospect);
            }
            if(ProspectsToUpdate.size() > 0){
                update ProspectMap.values();
            }
        }
    }
}
Yury BondarauYury Bondarau
Hi Gerald,

Trigger looks good and consumes only 1 SOQL query. Do you have any other logic in your SAVE method? Any other Workflows, Processes Triggers on i360__Appointment__c?

Also could you please provide the full stack trace?
SalesFORCE_enFORCErSalesFORCE_enFORCEr
There can be two reasons:
1. This trigger is getting invoked multiple times which may result in multiple execution of the same query.
2. The update in this trigger is executing other triggers/classes which are contributing in the 100 query limit per transaction.
Gerald HarmensGerald Harmens
The trigger is actually giving the error below, can you help me fix the code?

i360.ProspectTriggers: execution of AfterUpdate caused by: System.DmlException: Update failed. First exception on row 0 with id a0416000010g4SdAAI; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, Appointment_Price_Quoted: execution of AfterUpdate caused by: System.ListException: Duplicate id in list: a0Z1600000AQwFjEAL Trigger.Appointment_Price_Quoted: line 28, column 1: [] Class.i360.ProspectUtilities.UpdateProspectNames: line 1509, column 1 Class.i360.Prospect_Trigger_Utilities.ProspectChangeName: line 175, column 1 Trigger.i360.ProspectTriggers: line 22, column 1

 
trigger Appointment_Price_Quoted on i360__Appointment__c (after update) 
{
    if(Trigger.isAfter)
    {
        if(Trigger.isupdate)
        {
            set<Id> ProspectSet = new set<Id>();
            for(i360__Appointment__c Appointment :Trigger.new){
                ProspectSet.add(Appointment.i360__Prospect__c);
            }
            map<string, i360__Prospect__c> ProspectMap = new map<string, i360__Prospect__c>(
               [SELECT Id, Appointment_Quoted_Price__c 
               FROM i360__Prospect__c
                WHERE Id IN :ProspectSet]
            );
            list<i360__Prospect__c> ProspectsToUpdate = new list<i360__Prospect__c>();
            for(i360__Appointment__c Appointment : Trigger.new){
                i360__Prospect__c prospect = new i360__Prospect__c();
                Prospect.Id = ProspectMap.get(Appointment.i360__Prospect__c).Id;
                if(Appointment.i360__Quoted_Amount__c != NULL && Appointment.i360__Prospect__c != null){
                    prospect.Appointment_Quoted_Price__c = Appointment.i360__Quoted_Amount__c;
                }else{
                    prospect.Appointment_Quoted_Price__c = 0.00;
                }
                ProspectsToUpdate.add(prospect);
            }
            if(ProspectsToUpdate.size() > 0){
                update ProspectsToUpdate;
            }
        }
    }
}