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

Need Test Class For this trigger?

trigger trgr_Case_CaseCommentLock on CaseComment (before Update, before Delete) {
    List<Profile> currentUserProfile = new List<Profile>();
    currentUserProfile =
        [SELECT Name FROM Profile WHERE Id = :UserInfo.getProfileId() LIMIT 1];
        !currentUserProfile.isEmpty() &&
        currentUserProfile[0].Name != 'System Administrator'
            for(CaseComment cm : trigger.old)
                cm.addError('You cannot Delete a Case Comment!');
            for(CaseComment cm :
                cm.addError('You cannot Edit a Case Comment!');       

I have tried some thing but not worked.

the code which i have tried...

public class Test_CaseComments{

public static testMethod void main(){

//List<profile> Li = [SELECT Name FROM Profile WHERE Id = :UserInfo.getProfileId() LIMIT 1];
CaseComment cs = New CaseComment (); = 'TestOne';
        cs.Status = 'Open';  (picklist type)
        cs.Description = 'Test Case for test';
        cs.Origin = 'Annuity External'; (picklist type)
        cs.Type = 'Feature Request'; (picklist)
        cs.Business_Impact__c = 'No Impact';
        cs.Priority = 'Low'; (picklist)
        insert cs;
Best Answer chosen by Tillu
Carolina Ruiz MedinaCarolina Ruiz Medina
Hi Tillu,
I think your issue is that in your test you only insert but don't update. However your test is for : before Update, before Delete.

Then if in your test you do something like this :

   cs.Priority = 'Low'; (picklist)
   insert cs;

   cs.Description = 'Udating';
   update cs;

// and now the delete option
   delete cs;

Also I would like to share with you some links and video that I think for testing would help :
Test and Testability :
Unit testing with the domain layer :

Hope it helps :-) 

Kind Regards,