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
satyamsatyam 

Getting Too many SOQL because of method ,please help

Hi Everyone,

We have a requirement where we need to compare current Client support record with all the old client support record and that needs to be done before saving the record.

We need to compare near about 12 fields for every record which we are selecting during mass operation (can select 100 record for mass operation),but we are not having any field which can used as a key without saving the record.

We tried using map and list but we are getting exceptions ' Too many code statements: 200001' and as well as its making the process too time taking.

Please help to achieve this requirement .

 

Below is the method where we are getting issue:

 

public static Map<Client_support__c,List<String>> checkDuplicatePriceSupportforMassChangeone(List<Client_support__c> PSList){
                   
    List<String> duplicatesPS= new List<String>();    
    List<Client_support__c> OldPS=new List<Client_support__c>();
    oldPS =[select id,status__c,distributor_PRofile__c,Material_Selling__c,Material_Buying__c where status__c='Approved' or status__c='Awaiting distributor Approval' or status__c='Awaiting Nexeo Approval'];
    List <Client_support__c>l1 = new List<Client_support__c>();
    Map<Client_support__c,List<duplicate>> mapPS = new Map<Client_support__c,List<duplicate>>();
    List <String> l2=new List<String>();   
  for(Client_support__c ps:PSList){

    for(Client_support__c ps1:oldPS){

    if(ps.distributor_PRofile__c!=null){
        if(ps.distributor_PRofile__c == ps1.distributor_PRofile__c){
        l1.add(ps1);
    }
    }

    if(ps.Material_Selling__c!=null){
        for(Client_support__c li : L1){
       
            if(ps.Material_Selling__c == ps1.Material_Selling__c){
            //l1.add(li);
            l2.add(li.aggrement_number__c);
            }

        }
    }

   
    }
   
    mapPS.put(ps1 ,l2);

 }   

 

Thanks in advance:))))
                   
   

hitesh90hitesh90

Here,

checkDuplicatePriceSupportforMassChangeone(List<Client_support__c> PSList)

this method is call more than 100 times because of that it gives Too many SOQL