Activity Forums Salesforce® Discussions Why query is performed in between start test & stop test in Salesforce?

  • Why query is performed in between start test & stop test in Salesforce?

    Posted by Deepak on May 11, 2020 at 7:37 am

    Why query is performed in between start test & stop test in Salesforce?

    MOHIT replied 4 years, 6 months ago 3 Members · 2 Replies
  • 2 Replies
  • Kirandeep

    Member
    May 11, 2020 at 10:48 am

    To reset the governor Limits we use Test.startTest() and Test.stopTest() in Test Classes.

  • MOHIT

    Member
    May 11, 2020 at 2:29 pm

    Test.startTest() and Test.stopTest() exist basically to permit you to reset as far as possible inside the setting of your test execution and to have the option to test nonconcurrent strategies. These two proclamations can't be called more than once inside a testMethod. They are not required to be utilized yet in certain circumstances might be basic. Offbeat (@future) calls made during the test are additionally finished when you call Test.stopTest() permitting you to test the aftereffects of nonconcurrent conduct in your code.
    Given a situation where you have to execute various questions and countless DML pushes so as to set up the information for the genuine code being tested, it may be inconceivable for you to run your test without these announcements.
    For example in this anecdotal situation, if during the arrangement of your test you expected to execute 99 SOQL questions and supplement 9,999 records to seed the organization with the information your code required for legitimate testing, if Salesforce didn't offer an instrument to reset as far as possible the code which you are testing would just have space for one more SOQL inquiry and one more record in a DML proclamation before it would hit one of those two cutoff points (100 inquiries and 10,000 records prepared by DML explanations separately) and toss an exemption.
    In the above situation, if you somehow managed to call Test.startTest() after your 99 inquiries were finished and your 9,999 columns were DML'd - as far as possible inside your test would have returned to zero and by then the code which you are testing would be running in a setting that all the more intently looks like a solitary exchange's cutoff points, all things considered. This component permits you to "overlook" the work that must be done to set up the test situation.

Log In to reply.

Popular Salesforce Blogs

Popular Salesforce Videos