• Claire Field
  • NEWBIE
  • 15 Points
  • Member since 2016

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 1
    Replies
Hi!

I have a trigger that I got off a comment in the Success Community (thanks Subramani!) that adds Case Comments to Cases during the same import (rather than first importing Cases and then Case Comments based on the parent ID). The trigger is in the Sandbox and I am unable to deploy it because there is not enough code covereage. I am told that I need to have a test class for this trigger in order to be able to test and deploy it to Production. I am pretty new to SF administration and have almost no experience writing in Apex. Would anyone be able to help me create a test class for the following trigger?

trigger CreateCaseComment on Case (after insert) {

List<CaseComment > casecmlist=new list<CaseComment >();

for(Case c : Trigger.new){
     if(c.commentCL__c!= ''){

        CaseComment cc = new CaseComment();
        cc.commentBody = c.commentCL__c;
        cc.ParentId = c.Id;
        casecmlist.add(cc);
     }
 }
 if(casecmlist!=null){
 insert casecmlist;
 }
}

I really appreciate any assistance I can get! Thank you!
Hi!

I have a trigger that I got off a comment in the Success Community (thanks Subramani!) that adds Case Comments to Cases during the same import (rather than first importing Cases and then Case Comments based on the parent ID). The trigger is in the Sandbox and I am unable to deploy it because there is not enough code covereage. I am told that I need to have a test class for this trigger in order to be able to test and deploy it to Production. I am pretty new to SF administration and have almost no experience writing in Apex. Would anyone be able to help me create a test class for the following trigger?

trigger CreateCaseComment on Case (after insert) {

List<CaseComment > casecmlist=new list<CaseComment >();

for(Case c : Trigger.new){
     if(c.commentCL__c!= ''){

        CaseComment cc = new CaseComment();
        cc.commentBody = c.commentCL__c;
        cc.ParentId = c.Id;
        casecmlist.add(cc);
     }
 }
 if(casecmlist!=null){
 insert casecmlist;
 }
}

I really appreciate any assistance I can get! Thank you!