I am having an issue in writing a test class for the trigger below. I have started writing a test class for the trigger but the code coverage is still 0%. Am I missing something?


trigger trgApproveCIMaster on Approve_CI__c ( before update, after update ) 
    Set<Id> setCgmId = new Set<Id>();
    Set<Id> setGMid = new Set<Id>();
    Set<ID> editUserIDSet = ApproveCIDetailHandler.geteditUserIDDSet();

    List<CollaborationGroupMember> lstCgm = [SELECT Id,
                                                FROM CollaborationGroupMember WHERE CollaborationGroupId =: Label.CI_ID ];
    List<GroupMember> lstGm = [SELECT GroupId, UserOrGroupId 
                                       FROM GroupMember 
                                       WHERE GroupId =: Label.CIMS_LIB_USER_GROUP_ID]; 
        for(CollaborationGroupMember cgm : lstCgm)

        for(GroupMember gm: lstGm)

        //To fetch the Current User Name
        User usr = UserData.getUserInfo();
        Map<String,User> mapUserNames = new Map<String,User>();
        Map<String,User> mapSSOvsUsers = new Map<String,User>();
        list<User> listUsers = new list<User>(); 
        Set<String> SbmtrSSSOs = new Set<String>(); 
        Map<String, String> mapIdvsUsrName = new Map<String, String>();
        List<User> lstAllUsers = new List<User>();

        if(trigger.isbefore || trigger.isupdate )
            for(Approve_CI__c recApp:trigger.new)
                if(recApp.SSSO__c != null)

            lstAllUsers = [SELECT Id, Name, Email, FederationIdentifier FROM User];

            if( !lstAllUsers.isEmpty() )
                for(User u1 : lstAllUsers)
                    mapIdvsUsrName.put(u1.Id, u1.Name);
            //listUsers contains User info of the users(Reviewers and Submitters) in SbmtrSSSOs Set.
                for(User recUsr : listUsers)
                    mapSSOvsUsers.put(recUsr.FederationIdentifier, recUsr);
                //mapUserNames contains User name as key and User info as value.

My test class

    private class Test_trgApproveCIMaster {

         @isTest static void trgApproveCIMaster() {
            Approve_CI__c newUser = new Approve_CI__c(Approver__c = 'test', Status__c = 'Submitted', Name = 'testing', Submitted_By__c = 'testUser', SSSO__c = '000111222');
            insert newUser;

            //just to see output
            newUser = [select id , Approver__c, Status__c , Name, Submitted_By__c, SSSO__c from Approve_CI__c where id=:newUser.Id];

            //update record and test if ssso__c is null
            newUser.Status__c = 'Approved';
            update newUser;

            User newUser2 = new User(Email = '[email protected]');
            insert newUser2;    

            //add my System.asserts        

1 Answer 1


You need to insert and update Approve_CI__c object record as well since your trigger is on Approve_CI__c object.

After your insert newUser2, you need to add something like this.

Approve_CI__c app = new Approve_CI__c();
app.Name = 'test';
app.SSSO__c = '123456';
//all other required fields
insert app;

app.Name = 'test12345';
update app;

Of course, this is just a sample.

Follow this resource for more on test classes


You must log in to answer this question.