You need to sign in to do that
Don't have an account?
Paul 32
Struggling with test class for insert trigger
Hi I have the following trigger that sits on leads, what it does is clones a files and attaches it to the lead. I need to write a test class, but I can only cover 45%, the part that isnt covered is the ContentVersion insert. Any help would be appreciated.
trigger copyFiles on Lead (after insert) {
Lead lead = [Select AttachmentId__c From Lead where Id IN : Trigger.new];
if(lead.AttachmentId__c == Null){
//Do Nothing
} else {
Lead l = [Select Id, Patient_Referral_Id__c, AttachmentId__c From Lead where Id IN : Trigger.new];
ContentVersion cont = [SELECT Checksum,ContentDocumentId,ContentLocation,ContentSize,ContentUrl,
Description,FileExtension,FileType,FirstPublishLocationId,Id,IsAssetEnabled,
IsDeleted,Origin,OwnerId,PathOnClient,PublishStatus,RatingCount,ReasonForChange,
SharingOption,Title,VersionData,VersionNumber
FROM ContentVersion Where ContentDocumentId =: l.AttachmentId__c];
ContentVersion newcont = new ContentVersion();
newcont.Title = cont.Title;
newcont.PathOnClient = cont.PathOnClient;
newcont.VersionData = cont.VersionData;
newcont.FirstPublishLocationId = l.Id;
insert newcont;
}
}
trigger copyFiles on Lead (after insert) {
Lead lead = [Select AttachmentId__c From Lead where Id IN : Trigger.new];
if(lead.AttachmentId__c == Null){
//Do Nothing
} else {
Lead l = [Select Id, Patient_Referral_Id__c, AttachmentId__c From Lead where Id IN : Trigger.new];
ContentVersion cont = [SELECT Checksum,ContentDocumentId,ContentLocation,ContentSize,ContentUrl,
Description,FileExtension,FileType,FirstPublishLocationId,Id,IsAssetEnabled,
IsDeleted,Origin,OwnerId,PathOnClient,PublishStatus,RatingCount,ReasonForChange,
SharingOption,Title,VersionData,VersionNumber
FROM ContentVersion Where ContentDocumentId =: l.AttachmentId__c];
ContentVersion newcont = new ContentVersion();
newcont.Title = cont.Title;
newcont.PathOnClient = cont.PathOnClient;
newcont.VersionData = cont.VersionData;
newcont.FirstPublishLocationId = l.Id;
insert newcont;
}
}
Raj Vakati
Paul 32
Hi Raj V, thanks for your reply, unfortunatley this gets 0% coverage of the trigger. I also tried to insert the attachment before the lead, but this always results in 0 coverage.