You need to sign in to do that
Don't have an account?
Fresco
need to cover attachmnets in test class
class:
------
In my class attachments are like below
List<Attachment> kycAtt=[select id,name,body,BodyLength from Attachment where parentId=:kyc.Id and BodyLength>0];
List<Attachment> erpAtt=[select id,name,body,BodyLength from Attachment where parentId=:erp.Id and BodyLength>0];
Messaging.EmailFileAttachment[] efaList=new Messaging.EmailFileAttachment[] {};
if(kycAtt.size()>0){
for(Attachment att:kycAtt){
Messaging.EmailFileAttachment efa = new Messaging.EmailFileAttachment();
efa.setFileName(att.name);
efa.setBody(att.body);
efaList.add(efa);
}
}
if(erpAtt.size()>0){
for(Attachment att:erpAtt){
Messaging.EmailFileAttachment efa = new Messaging.EmailFileAttachment();
efa.setFileName(att.name);
efa.setBody(att.body);
efaList.add(efa);
}
}
if(efaList.size()>0){
mail.setFileAttachments(efaList);
}
I need to cover these code in test line can you plese help me out
------
In my class attachments are like below
List<Attachment> kycAtt=[select id,name,body,BodyLength from Attachment where parentId=:kyc.Id and BodyLength>0];
List<Attachment> erpAtt=[select id,name,body,BodyLength from Attachment where parentId=:erp.Id and BodyLength>0];
Messaging.EmailFileAttachment[] efaList=new Messaging.EmailFileAttachment[] {};
if(kycAtt.size()>0){
for(Attachment att:kycAtt){
Messaging.EmailFileAttachment efa = new Messaging.EmailFileAttachment();
efa.setFileName(att.name);
efa.setBody(att.body);
efaList.add(efa);
}
}
if(erpAtt.size()>0){
for(Attachment att:erpAtt){
Messaging.EmailFileAttachment efa = new Messaging.EmailFileAttachment();
efa.setFileName(att.name);
efa.setBody(att.body);
efaList.add(efa);
}
}
if(efaList.size()>0){
mail.setFileAttachments(efaList);
}
I need to cover these code in test line can you plese help me out
I cant provide the exact code for your problem becuase I do not no what type of objects you are referring to by varaibles kyc and erp , but what you have to do is quite simple,
1. Define a test class and test method
2 in your test method insert two records of kyc and erp
3. then create two attachment records linking to above records via parent id
4. insert those attachment records
5 call your method from test class
refer below code for creating attachment in test method.