You need to sign in to do that
Don't have an account?
Jarvis Howard
How to write a test class with 100% coverage
Hey everyone, I'm not a developer, but have managed to write this test class which works well in Sandbox, but don't know how to write a test class.
Also - is there any way I can get this to save to 'files' rather than just 'attachments'?
Code is below:
public class OrderAttachPDFExt{
ApexPages.StandardController controller;
public Order order {get;set;}
public PageReference rtn;
public OrderAttachPDFExt(ApexPages.StandardController c){
order = (Order)c.getRecord();
rtn = c.view();
}
public PageReference attachOrderGeneratePDF() {
/* Get the page definition */
PageReference pdfPage = Page.OrderGeneratePDF;
pdfPage.getParameters().put('id',order.id);
/* generate the pdf blob */
Blob pdfBlob = pdfPage.getContent();
/* create the attachment against the offer */
Attachment a = new Attachment(parentId = order.id, name=order.OrderNumber +'.pdf', body = pdfBlob);
/* insert the attachment */
insert a;
/* send the user back to the offer detail page */
return rtn;
}
}
Also - is there any way I can get this to save to 'files' rather than just 'attachments'?
Code is below:
public class OrderAttachPDFExt{
ApexPages.StandardController controller;
public Order order {get;set;}
public PageReference rtn;
public OrderAttachPDFExt(ApexPages.StandardController c){
order = (Order)c.getRecord();
rtn = c.view();
}
public PageReference attachOrderGeneratePDF() {
/* Get the page definition */
PageReference pdfPage = Page.OrderGeneratePDF;
pdfPage.getParameters().put('id',order.id);
/* generate the pdf blob */
Blob pdfBlob = pdfPage.getContent();
/* create the attachment against the offer */
Attachment a = new Attachment(parentId = order.id, name=order.OrderNumber +'.pdf', body = pdfBlob);
/* insert the attachment */
insert a;
/* send the user back to the offer detail page */
return rtn;
}
}
For increasing the code coverage you will have to implement different cases so that all the scenarios are tested in the test class.
I hope this was helpful.
Regards,
Anutej
Thanks for that - are you able to give me some pointers on how to do that?
I've not written a test class before!
Regards,
Jarvis
>> https://trailhead.salesforce.com/en/content/learn/modules/apex_testing/apex_testing_intro
>> https://www.sfdc99.com/2013/05/14/how-to-write-a-test-class/
Do let me know if this helps and in case if you need any help let me know.