You need to sign in to do that
Don't have an account?
Thomas Kayser-Eichberg
how to test my class (render VF Pages as PDF and Attach file to record)
Hi everyone,
I am totally newbie to salesforce and apex. As I already managed to find a way to render a visualforce page to pdf and attach it by class to the record. This runs perfect in Sandbox. I dont get it to production instance due to the fact I dont even know how to test it.
Can anybody help me out generating a test class for my class?
would be so great to get it running. Thx to all!
Here is my Code:
public class quotePDFExtension {
ApexPages.StandardController controller;
public Quote quote {get;set;}
public PageReference rtn;
public quotePDFExtension(ApexPages.StandardController c){
quote = (Quote)c.getRecord();
rtn = c.view();
}
public PageReference attachQuotePDF() {
/* Get the page definition */
PageReference pdfPage = Page.angebot;
pdfPage.getParameters().put('id',quote.id);
/* generate the pdf blob */
Blob pdfBlob = pdfPage.getContent();
/* create the attachment against the offer */
Attachment a = new Attachment(parentId = quote.id, name=quote.Angebot_Nr__c + '.pdf', body = pdfBlob);
/* insert the attachment */
insert a;
/* send the user back to the offer detail page */
return rtn;
}
}
I am totally newbie to salesforce and apex. As I already managed to find a way to render a visualforce page to pdf and attach it by class to the record. This runs perfect in Sandbox. I dont get it to production instance due to the fact I dont even know how to test it.
Can anybody help me out generating a test class for my class?
would be so great to get it running. Thx to all!
Here is my Code:
public class quotePDFExtension {
ApexPages.StandardController controller;
public Quote quote {get;set;}
public PageReference rtn;
public quotePDFExtension(ApexPages.StandardController c){
quote = (Quote)c.getRecord();
rtn = c.view();
}
public PageReference attachQuotePDF() {
/* Get the page definition */
PageReference pdfPage = Page.angebot;
pdfPage.getParameters().put('id',quote.id);
/* generate the pdf blob */
Blob pdfBlob = pdfPage.getContent();
/* create the attachment against the offer */
Attachment a = new Attachment(parentId = quote.id, name=quote.Angebot_Nr__c + '.pdf', body = pdfBlob);
/* insert the attachment */
insert a;
/* send the user back to the offer detail page */
return rtn;
}
}
Take a look into this link http://amitsalesforce.blogspot.com/2015/06/best-practice-for-test-classes-sample.html. You will get idea how to write test class for your class.
Thanks,
Dhanya
actually I'll get a 36% Coverage which isn't enough. Maybe you or anybody else can give me a hint to get it done?
My Class
my test Class
Big Thanks
Thomas