You need to sign in to do that
Don't have an account?

Apex Test Class Error Error: Compile Error: Constructor not defined
Hello Friends,
I got stuck in creating a Test Class. Getting error when saving the test class.
indly need your inputs to troubleshoot the error. Below is nmy Class and Test Class.
Thanks in Advance.
I got stuck in creating a Test Class. Getting error when saving the test class.
indly need your inputs to troubleshoot the error. Below is nmy Class and Test Class.
Class::: public with sharing class victoriaBuildPDF { private final Order o; public victoriaBuildPDF(ApexPages.StandardController standardPageController) { o = (Order)standardPageController.getRecord(); } public PageReference savePdf() { PageReference pdf = Page.victoriaBuild; pdf.getParameters().put('id',o.id); Blob pdfBlob; if (!Test.isRunningTest()) { pdfBlob = pdf.getContent(); } else { pdfBlob = Blob.valueOf('PDF Test...'); } Attachment attach = new Attachment(parentId = o.Id, Name = 'VictoriaBuild.pdf', body = pdfBlob, IsPrivate = false); insert attach; PageReference detailPage = new ApexPages.StandardController(o).view(); detailPage.setRedirect(true); return detailPage; } }
Test Class::: @isTest private class victoriaBuildPDF_Tests { private static testMethod void testSaveAndAttachPDF() { Account acc = new Account(Name = 'Test Account'); insert acc; Order a = new Order(AccountId = acc.Id, EffectiveDate = system.today(), Status = 'Draft'); insert a; ApexPages.currentPage().getParameters().put('Id', a.Id); victoriaBuildPDF con = new victoriaBuildPDF(); con.savePDF(); } }Error: Error: Compile Error: Constructor not defined: [victoriaBuildPDF].<Constructor>() at line 12 column 28
Thanks in Advance.
Greetings to you!
You are using StandardController, so you need to construct the standard controller.
Please try the below code, I have tested in my org and it is working fine. Kindly modify the code as per your requirement.
I hope it helps you.
Kindly let me know if it helps you and close your query by marking it as solved so that it can help others in the future. It will help to keep this community clean.
Thanks and Regards,
Khan Anas