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
Zaki KZaki K 

test cases

Hi all.

here is my code . how can i achieve 100% code coverage for this Trigger?



trigger CopyAttachments on SVMXC__Service_Order__c(after insert)
{
 //Attachment[] attList = [select id, name, body from Attachment where ParentId = :Trigger.new[0].SVMXC__Case__c];
 Attachment[] insertAttList = new Attachment[]{};
 
         for(Attachment a: [select id, name, body from Attachment where ParentId = :Trigger.new[0].SVMXC__Case__c])
         {
               Attachment att = new Attachment(name = a.name, body = a.body, parentid = Trigger.new[0].id);
               insertAttList.add(att);
         }
       if(insertAttList.size() > 0)
       {
            insert insertAttList;
       }
 
}
subramanyam subbu 7subramanyam subbu 7
simple  create reference for ur class in test class.
Rashi Garg 30Rashi Garg 30
Try creating test class with following code


static testMethod void testAttachments() {
Case cse=new Case();
insert cse;

Attachment attach=new Attachment();
attach.Name='Unit Test Attachment';
Blob bodyBlob=Blob.valueOf('Unit Test Attachment Body');
attach.body=bodyBlob;
attach.parentId=cse.id;
insert attach;

List<Attachment> attachments=[select id, name from Attachment where parent.id=:cse.id];
SVMXC__Service_Order__c svmxOrder = new SVMXC__Service_Order__c(SVMXC__Case__c = cse.id);
insert svmxOrder;

System.assertEquals(1, attachments.size());
}