Can someone tell me how I can avoid using (seealldata=TRUE) BUT still be able to access an existing Chatter Group in a test class?
Example with use of the SeeAllData=TRUE clause;
//Find Chatter Group ID
CollaborationGroup BCIGroup = [Select Id,Name
FROM CollaborationGroup
WHERE Name = 'All Company'
LIMIT 1];
I am trying to add users to the group in my class but I run into a problem when creating the group, when seealldata is FALSE, because the test class still sees the chatter group to some degree. The group exists in both my sandbox and production environment.
Let me know if you want to see any of my code. This is part of a big chunk of code and there are a few classes involved so don't want to blast the forum with all the code.
Best Answer
It can be fairly simple to test these kind of data dependencies by shifting the source of the dependency slightly. For example, you could configure the
Name
you filter on so you can modify it in your test. Something like:Then in your test, you can just create your own group and change the name to match.
Note that because of the lazy loading pattern, you can pull this variable as many times as you want and it will consume just one query.