Hello All,
I am working on developing a custom apex class to help me out with a new flow that I created.
I am running into an issue where I cannot deploy my Apex Class to my production org because my 'code coverage' is 0% with my org's default tests. So I am in the process of creating an apex class to test it.
The Apex Class that I am using works in my sandbox, flow debug mode, and the execute anonymous window, however; it does not work when I preform the "Run Test" in the developer console.
This is the query that I am using. For testing purposes I have specified the group "Test Group For Apex Class Test" , but normally this is a variable.
SELECT ID FROM CollaborationGroup WHERE Name='Test Group For Apex Class Test'
This query executes properly and returns the ID of the group as expected:
0F9VA0000001DjB0AU
Here is the apex class itself:
public class ChatterGroupUtility{ @InvocableMethod(label='Get ChatterGroup ID' description='Returns the ID value of a given Chatter Group') public static List<String> getID(List<String> entry) { List<String> returnVar = new List<String>(); CollaborationGroup CG = [SELECT ID FROM CollaborationGroup WHERE Name=:entry]; returnVar.add(CG.Id); return returnVar; }}And here is the test class that I created (the check.add with the ID from above will be used to assert against the query during the test... but I haven't even gotten past the initial 'List has no rows' error):
@isTestpublic class ChatterGroupUtilityTest { @isTest private static void getIDTest(){ List<String> entry = new List<String>(); List<String> check = new List<String>(); entry.add('Test Group For Apex Class Test'); check.add('0F9VA0000001DjB0AU'); List<String> CG_ID = ChatterGroupUtility.getID(entry); }}I have been pounding my head against a wall for the past 3 hours on this and I'm really confused why it isn't working at this point. I have tried several variants of both my original apex class and the test and still the same result.
Use test class:
@isTest
public class ChatterGroupUtilityTest {
@isTest
private static void getIDTest() {
CollaborationGroup testGroup = new CollaborationGroup(
Name = 'Test Group For Apex Class Test',
CollaborationType = 'Private' // or 'Public' based on your use case
);
insert testGroup;
List<String> entry = new List<String>();
entry.add('Test Group For Apex Class Test');
List<String> check = new List<String>();
check.add(testGroup.Id);
List<String> CG_ID = ChatterGroupUtility.getID(entry);
System.assertEquals(check, CG_ID);
}
}