You need to sign in to do that
Don't have an account?
dev_002
apex test class to attach quote.
I friends, i'm very new to apex, somehow i managed to create a apex class to attach our custom quote (after some research on developer forum). But i'm unable to create a apex test class. I would very much appreciate if anyone could be able to help me out on this.
Thank you very much
public class quoteExt {
ApexPages.StandardController controller;
public Quote q {get;set;}
public quoteExt(ApexPages.StandardController controller)
{
controller = controller;
q = (Quote) controller.getRecord();
}
public quoteExt(){}
public PageReference attactQuote()
{
PageReference pdfPage = Page.quotationPDF;
Blob pdfBlob = pdfPage.getContent();
QuoteDocument a = new QuoteDocument (quoteid=q.id, Document=pdfBlob);
insert a;
PageReference detailPage = new PageReference('/../'+ q.id);
detailPage.setRedirect(true);
return detailPage;
}
static testmethod void basicAttachTest() {
/* Construct the standard controller for quote. */
ApexPages.StandardController con = new ApexPages.StandardController(new Quote());
quoteExt ext = new quoteExt(con);
}
}
Hi Dev,
Try something like this :
Please note it will only increase your code coverage, but to test it properly you have to put assert with your custom data in test method.
Thanks
Ankit Arora
Blog | Facebook | Blog Page
I have the same problem and I am not able to find a solution.
Error: Constructor not defined: [ApexPages.StandardController].<Constructor>(ApexPages.StandardController)
public class quoteExt {
ApexPages.StandardController controller;
public Quote q {get;set;}
public QuoteExt(ApexPages.StandardController c) {
controller = c;
q = (Quote) c.getRecord();
}
public PageReference attachQuote() {
/* Get the page definition */
PageReference pdfPage = Page.quotePDF;
/* set the quote id on the page definition */
pdfPage.getParameters().put('id',q.id);
/* generate the pdf blob */
Blob pdfBlob = pdfPage.getContent();
/* Create the quoteDocument */
QuoteDocument qd = new QuoteDocument(QuoteId = q.id, Document = pdfBlob);
/* insert the attachment */
insert qd;
/* send the user back to the quote detail page */
return controller.view();
}
static testmethod void basicAttachTest() {
Quote obj = new Quote() ;
insert obj ;
//Create a new instance of standard controller
ApexPages.StandardController sc = new ApexPages.standardController(obj);
/* Construct the standard controller for quote. */
ApexPages.StandardController con = new ApexPages.StandardController(sc);
quoteExt ext = new quoteExt(con);
PageReference pg = con.attachQuote() ;
}
}