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
TEJA M 19TEJA M 19 

I used for loop for insertion, i did nt use any soql query then why i m getting System.LimitException: Too many SOQL queries: 101

Hi I m little confused with the difference between issued and Dml Statements,Total number of SOQL queries issued 100, Total number of DML statements issued 150. i used FOR loop for insertion, I know its not best practice, I m trying to learn possibilities, I did nt use any soql query then why i m getting System.LimitException: Too many SOQL queries: 101, but insert is DML operation right? it should hit DML Exception 151? someone please explain me this.  

public class accountinse {
    
    public PageReference show(){
        List<Account> ac=new List<Account>();
        for(Integer i=0; i<200; i++){
            
            
            a.Name='testing12535'+i;
            a.AccountNumber='4857885';
            a.Type='Prospect';
            a.Industry='Biotechnology';
            a.AnnualRevenue=158758;
            a.Rating='cold';
            a.Phone='18578558';
            a.Identity_Proof__c='Adhar Card; PAN Card';
            a.Last_Name__c='a';
            ac.add(a);
        
        }
        insert ac;
        return null;
    }

}
Kai Herng LauKai Herng Lau
Hi,

Do you have any others trigger to listen on Account insert?
v varaprasadv varaprasad
Hi Teja,

I think in above class you are not having any issue,
Please check once in debug logs may be after inserting records some other triggers are fired.

please check once any triggers are existing on account object.

Please let me know in case of any help.

Thanks
Varaprasad



 
Salesforce DeveloperSalesforce Developer
The above code has issues, it wont run. You haven't initialized account, update as below :
public class accountinse {
    
    public PageReference show(){
        List<Account> ac=new List<Account>();
        for(Integer i=0; i<200; i++){
            
            Account a = new Account();
            a.Name='testing12535'+i;
            a.AccountNumber='4857885';
            a.Type='Prospect';
            a.Industry='Biotechnology';
            a.AnnualRevenue=158758;
            a.Rating='cold';
            a.Phone='18578558';
            a.Identity_Proof__c='Adhar Card; PAN Card';
            a.Last_Name__c='a';
            ac.add(a);
        
        }
        insert ac;
        return null;
    }

}
Now if you run this code, you wont get any Too many SOQL queries limit exception and the No of DML statements is 1 only, so you wont hit the DML statement limit as well. Check if there is any trigger which is firing on Account Insert that may be hitting these limits. 
TEJA M 19TEJA M 19
Hi Kai Herng Lau, I habe Before Insert trigger for Field updation and after trigger for Insertion of Contact with same values. 
Kai Herng LauKai Herng Lau
Hi TEJA M 19,

That may be the reason you get too many SOQL limit. Can I suggest you to disable the trigger or workflow if you have and run again your current code. If the code pass without any error that mean one of your automation causing the problem. Maybe you can use the trigger.OldMap to avoid infinite looping in the code. If you do mind you can share your trigger code here.

Hope this help.
TEJA M 19TEJA M 19
Hi All, This is my Account Trigger.

trigger AccountTrigger on Account (Before Insert,before update,after insert,after update) {
    
    
   if(trigger.isbefore){
       if(trigger.isinsert)
       {
          Accounttriggerhelper.setdefaultvalue(trigger.new);
       } 
       if(trigger.isupdate)
       {
            Accounttriggerhelper.setdefaultvalue(trigger.new);
       } 
    }
    
    
    if(trigger.isafter){
        if(trigger.isinsert)
        {
            Accounttriggerhelper.Insertcontactfornewaccount(trigger.new);
            Accounttriggerhelper.Insertcontactfornewaccount(trigger.newmap);} 
       if(trigger.isupdate)
       {
           //After Update logic
       } 
    }
}


public class Accounttriggerhelper
{
    public static void setdefaultvalue(list<account> getnewaccount)
    {
        for(account acc:getnewaccount)
        { 
           if(acc.Rating==null)
        {
        acc.addError('Please Select Rating');
        }
        
        
            if(acc.Rating=='Hot')
            {
                acc.Shippingcity='Chennai';
            }
            else if(acc.Rating=='Warm')
            {
                acc.Shippingcity='Hyderabad';
            }
            else 
            {
                acc.Shippingcity='Bangalore';
            }
            
        }
    }
    
  
    public static void Insertcontactfornewaccount(list<account> getnewaccount)
    {
        List<contact> insertContact=new List<contact>();
        for(account acc:getnewaccount)
           {
               Contact con =new contact();
               con.Firstname=acc.Name;
               con.LastName=acc.Last_Name__C;
               con.phone=acc.phone;
               con.AccountId=acc.id;
               insertContact.add(con);
           }
           insert insertContact;
    }
    public static void Insertcontactfornewaccount(Map<id,account> getnewaccount)
    {
       
    }
}
TEJA M 19TEJA M 19
Thanks Mr. Varaprasad
TEJA M 19TEJA M 19
Salesforce Developer actually while copying that code i forgot to paste that. in my actual code i use For(Account a:acc){ }. I wanted chick if i can insert more than 100. so used Integer For(I; i<200; i++){}.  My doubt is i did nt use any soql queries and only one DML action i used still i m hitting governer limits System.LimitException: Too many SOQL queries: 101. 

regards
Teja M
TEJA M 19TEJA M 19
I m able to insert after inactivate my trigger. what would be the reason can anyone tell me Please. 

Thank you,
Teja M
Kai Herng LauKai Herng Lau
Hi,

I can see in your Accounttriggerhelper class has insert contact record. Do you mind to check if you have any trigger, workflow or Process builder under contact? 
TEJA M 19TEJA M 19
Hi,

I dont have any triggers or worflows under contact.