function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Mohammed SiddiqueMohammed Siddique 

"Code Coverage Error” Need to add Test classes for existing code

I found an application in AppExchange (Group Alerts for Chatter), this app works like a triggers whenever specified records is changed or updated it triggers a Chatter post notifications to Chatter Groups. This works only on standard objects but while googling I found there is a template which lets you add custom object as well, with the help of Apex coding template I was able to add custom object in the Group Alerts for Chatter in my sandbox and when tried pushing the setting to production Org I’m getting an error which say “Code Coverage Error” it says we need to add Test classes for existing code. Need assistance adding test classes.

Thanks in advance....
Mohammed SiddiqueMohammed Siddique
*******************Here is an Apex coding template if you wanna have a look******************

trigger ProjectGroupAlert on Project__c (after insert, after update) {
 
    try {
        //prevent massive updates in case of batch update
        if (trigger.new.size() < 10) {
            Set<ID> userIds = new Set<ID>();
            Set<ID> accountIds = new Set<ID>();
 
            for (Project__c rec : Trigger.New) {
                userIds.add(rec.OwnerId);
                userIds.add(rec.CreatedById);
                userIds.add(rec.LastModifiedById);
                //OPTIONAL: assuming your record has a relationship with Account
                accountIds.add(rec.Account__c);
            }
 
            GroupAlert.GroupAlert gAlert =
                new GroupAlert.GroupAlert('Project__c', Userinfo.getUserId(),
                    UserInfo.getProfileId(), UserInfo.getUserRoleId());
 
            //This section allows the Group Alerts engine to substitute a Lookup Field ID
            //(OwnerId, CreatedById,  LastModifiedById) with the Related Object's Name
            List<User> users = [SELECT ID, Name FROM User WHERE ID IN :userIds];
            gAlert.addRelatedLookups(users, 'Name');
 
            //OPTIONAL: Doing the same here with Accounts. You can do this with any
            //lookup field where you want to show a field on the related record
            //rather than the ID
            List<Account> accounts = [SELECT ID, Name FROM Account WHERE ID IN :accountIds];
            gAlert.addRelatedLookups(accounts, 'Name');
 
            gAlert.postToChatterGroup(Trigger.newMap, Trigger.oldMap);
        }
    } catch (Exception e) {
        //Do no harm :)
    }
}