I have multiple Test classes that has duplicate code. One of the methods is to create opportunity records. Can I create a separate class that does this by itself and reference it from the Test classes?
Tell me more
×
Salesforce Stack Exchange is a question and answer site for
Salesforce administrators, implementation experts, developers and anybody in-between. It's 100% free, no registration required.
Short answer:YES! Long Answer:It's the same as with any reusable code, just create another class and add your method:
You can then call this method from any of your other test methods to setup data:
|
|||
|
|
|
You can definitely do this, I always do this for my frequently used objects. You can just create a standard public class and then call it from your test classes. Because it gets called a lot, the test coverage for the class is generally going to be near 100%. I typically do the following:
Then in your test class,
And reference the account as
Variations are obviously possible, this is a start... |
|||||||
|