You need to sign in to do that
Don't have an account?
TEJA 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;
}
}
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;
}
}
Do you have any others trigger to listen on Account insert?
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
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.
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)
{
}
}
regards
Teja M
Thank you,
Teja M
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?
I dont have any triggers or worflows under contact.