You need to sign in to do that
Don't have an account?
Subodh Shukla
How to cover this lines of code in test class:
public void updateAttachmentWithLDCNumber(Map<String, String> mapAccount_LDCValue){ List<Attachment> lstAttachmentToUpdate = new List<Attachment>(); List<Attachment> lstAttachment = [SELECT Id, Name, Body, ParentId FROM Attachment WHERE ParentId IN: mapAccount_LDCValue.keySet()]; if(lstAttachment.isEmpty()) return; for(Attachment objAttachment : lstAttachment){ Blob csvBody = objAttachment.body; if(csvBody == null) continue; String strCSVBody = csvBody.toString(); List<String> lstRows = strCSVBody.split('\n'); Integer columnIndex = null; String finalCSV = lstRows[0]; List<String> lstHeader = finalCSV.split(','); for(Integer i = 0; i < lstHeader.size(); i++){ if(lstHeader[i].contains('LDCNumber')){ columnIndex = i; break; } } if(columnIndex == null) continue; for(Integer i = 1; i < lstRows.size(); i++){ List<String> lstCoumn = lstRows[i].split(','); lstCoumn.set(columnIndex, mapAccount_LDCValue.get(objAttachment.ParentId)); finalCSV += '\n' + String.join(lstCoumn, ','); } objAttachment.body = Blob.valueOf(finalCSV); lstAttachmentToUpdate.add(objAttachment); } update lstAttachmentToUpdate; }
use below Ttest class Code Coverage 90%
Note : AttachmentWithLDCNumber this is your class name
Hope this will help you,
Mark Best ANSWER if its works for you,
Thanks
karthik
Use this Test class.. 100% code Coverage,
Note : AttachmentWithLDCNumber-- Class name replace your class here
AttachmentWithLDCNumber TstCon= new AttachmentWithLDCNumber();
Mark Best ANSWER if its works for you,
Thanks
karthik