I can assure you that I have looked at dozens, if not hundreds of blogs, articles and questions related to SOQL limitation problems, but have not found the answer that I'm looking for. Please hear me out.
I have built a custom SalesForce Quote/Order/Change Order process using only custom objects. The only standard object that we use is Leads, and even those are soon to go.
My problem is that our sales process is massive and includes many VisualForce pages and triggers. All of the data originates in the Lead and transforms many times through the sales process. In addition, our product type is very complex and requires 10 custom objects to facilitate. I would like my test class to not rely on any existing data because this is best practice, and I don't want to have to maintain dummy data.
So, in order to test all of my code, I need to be able to do the following in a single test:
- Generate a subset of our product data.
- Create a Lead
- Work through the entire massive sales process from start to finish
Here are the problems I'm facing:
- By the time I've gotten all of the way through to the end of the process I am well over my SOQL limits.
- Though I would like to break my test classes up, the final portion of my sales process (Orders and Change Orders) rely on data that is generated by triggers and visualforce pages which would have fired previously in the test. There is no way for me to break up the test and still access all of the generated data that I need.
- I've played with
Test.startTest()
andTest.stopTest()
with some success, but since I can only have one test class, I can only use these once.
What I have tried
- I have moved the
start/stopTest()
methods to various positions in my test to try and leverage as many calls as possible - I have attempted to use multiple methods within a single class (fig 1) so that I can use the
start/stopTest()
methods multiple times. This doesn't work because I can't reference the data from one method to the next. - I have tried chaining methods (fig 2), but this doesn't work because test methods need to be
static void
(I believe).
I'm hoping that I have totally misunderstood how test methods are supposed to work and that someone can lead me down the correct path. What I suspect people will say is that I need to split up my class -- but I really can't do that with out creating dummy data which would need to be manually maintained. I would really like to avoid @isTest(SeeAllData=true)
.
fig 1
private class OrderTest {
@isTest static void orderProcess1() { ... }
@isTest static void orderProcess2() { ... }
@isTest static void orderProcess3() { ... }
}
fig 2
private class orderTest {
@isTest static void createLead() {
Lead newLead = new Lead ( ... );
// Begin next method
convertLead(newLead);
}
@isTest static void convertLead(Lead newLead) {
Test.startTest();
// Convert Lead
Test.stopTest();
}
}
I can assure you that I have looked at dozens, if not hundreds of blogs, articles and questions related to SOQL limitation problems,
and a well-written question , nicely-styled question. If only everyone would be so good. BTW -seeAllData=true
is never,never a good idea (except in very limited situations where mocking of certain standard objects is impossible) and you should mentally associate that @istest annotation with putting your finger in an electric outlet.