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
Apex developer 21Apex developer 21 

Help wrinting a tesclass for extended controller attachment PDF

Im a newbie, can someone help me writing a test class for an extended controller PDF attachment see:
 
public with sharing class attachPDF {
private final Facturatie__c a;
    public attachPDF(ApexPages.StandardController standardPageController) {
        a = (Facturatie__c)standardPageController.getRecord();
    }    
    Facturatie__c  currentRecord = [SELECT Id, Accountname__r.Name FROM Facturatie__c WHERE Id = :ApexPages.currentPage().getParameters().get('id')];
    
    public PageReference attachPDF() {
        PageReference pdfPage = Page.Factuur2PDF;
        pdfPage.getParameters().put('id',a.id);
        Blob pdfBlob = pdfPage.getContent();
        
        Attachment attach = new Attachment(parentId = a.Id, Name = 'Factuur ' + '-' + currentRecord.Accountname__r.Name +'-'+ date.today().format() +'.pdf', body = pdfBlob); //create the attachment object
        insert attach;
        PageReference pageWhereWeWantToGo = new ApexPages.StandardController(a).view();
        pageWhereWeWantToGo.setRedirect(true);
        return pageWhereWeWantToGo;
    }
}