LoginSignup
0
0

More than 1 year has passed since last update.

Test Apex Class でのToo many SOQL queries: 101エラー

Last updated at Posted at 2021-01-18

トリガが設定されているオブジェクトを複数つかってテストをしていると、ちょっと困ったエラーです。
クエリーが101回に達しました。

困りましたねぇ、テストデータを作るとどうしてもトリガが走ってしまいます。

以下に解決策がありました。
https://salesforce.stackexchange.com/questions/105372/too-many-soql-queries-101-issue-with-unit-test-methods

By using the Test.startTest() & Test.stopTest() you get 2X governer limits.

In nutshell you have 2 context.

out side of Test.startTest() & Test.stopTest() and
inside of Test.startTest() & Test.stopTest().
In both context you get separate limits.

Test.startTest() & Test.stopTest()で囲まれた中とそうでない部分ではそれぞれ別個に
101個の制限がある。
よって、うまく分けたらいいみたいです。

確かに、適当なところで分けると問題なくテストできました。

他の回答ではトリガのSOQLを整理しろとかあったけど、それができたら苦労しないよ。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0