public without sharing class BatchSelectRepairPDFDelete {
    public void deletePDF(List<Repair__c> repList){
    	List<String> attachmentNameList = new List<String>();
        List<Attachment> isGeneratedPDFList = new List<Attachment>();
    	for(Repair__c re : repList){   
          	attachmentNameList.add(re.name + '_' + 'MaintenanceCommission.pdf');
        }
        isGeneratedPDFList = [select id from Attachment where name IN:attachmentNameList];
        System.debug(LoggingLevel.INFO, '*** isGeneratedPDFList: ' + isGeneratedPDFList);
        if(isGeneratedPDFList.size() > 0){
            delete isGeneratedPDFList;
        }
    }

    public void createPDF(List<Repair__c> repList){
    	PageReference pdfPage;
        List<Attachment> attachments = new List<Attachment>();
    	for(Repair__c re : repList){       
          	pdfPage = new PageReference('/apex/MaintenanceCommissionPDF?id=' + re.Id);
            Blob pdfBody;
            if(System.Test.isRunningTest()) { 
                pdfBody = blob.valueOf('Unit.Test');
            } else {
                pdfBody = pdfPage.getContentAsPDF();
            }
            Attachment attach = new Attachment();
            attach.Body = pdfBody;
            attach.Name = re.name + '_' + 'MaintenanceCommission.pdf';
            attach.ParentId = re.id;
            attachments.add(attach);
        }
        System.debug(LoggingLevel.INFO, '*** attachments: ' + attachments);
        insert attachments;
    	}
}