+ Start a Discussion
Adarsh NandanAdarsh Nandan 

Getting a Too many Soql Error Exception In Production

I am getting a too many Soql  queries Exception  in production but not in sandbox . Then  what can i do ? its too emegency .
NagendraNagendra (Salesforce Developers) 
Hi Adarsh,

As an always System.LimitException: Too many SOQL queries: 101 is hard to find. An error does not return you at what place is the problem but those that cause SOQL number 101. So you have to investigate ALL code around this action.

May I suggest you please remove the SOQL queries and DML queries if you have written in the for loop.Writing the above queries in for loop will hit the governor limits due to which the above error is caused.

Hope this helps.

Please mark this as solved if it's resolved so that it gets removed from the unanswered queue which results in helping others who are encountering a similar issue.

Amit Singh 1Amit Singh 1
When are you getting the error? It may be that you do not have many records in the sandbox that is why you are not getting the error into Sandbox, Please make sure that you have bulkified your code. Visit below link.
Harsh Aditya 21Harsh Aditya 21
Addition to above answers
Don't use (SeeAlldata=true) in test class
Mustafa JhabuawalaMustafa Jhabuawala
If you are writing the query in for loop then you have to remove it.

But as you mentioned it is working in sandbox but not in production - It seems that you have inner query.

There is limit for inner query too. Can you share your query so that I can give my inputs.
Sukanya BanekarSukanya Banekar

Check if you are writting query inside for loop. Also If you have multiple triggers for one object you should write only one trigger for one object. 

Sukanya Banekar