You need to sign in to do that
Don't have an account?
Katharine Anderson 13
Test code for webservices method
Okay, I think I'm a little over my head and I could use some guidance. This is one of my first major coding projects and I have hit a wall.
My goal is for my users to be able to look at a listview, select several records, and then click a button that will create pdfs from those records, attach them to the records, and then take the attachment and upload it to the Box folder associated with that record's parent.
I have uploaded all of my code to this gist: https://gist.github.com/AndersonKatharineTNC/fe722b94215efe76d7be7b0d807d9e5b
I have two major issues that I would like help solving:
1) Test_PdfGeneratorController errors out because the savePdf() method in PdfGeneratorController2 is a webservices method and it needs do do a mock webservices callout. I generated the wsdl2apex class for PdfGeneratorController2, and I created a test class called WebServiceMockImpl which does the mock response to the callout, but I can't figure out how to get the mock callout to happen in Test_PdfGeneratorController in order to cover the savePdf() method.
2) The Attach Monitoring PDF button currently only works as a detail page button. I'd like to update the code in PdfGeneratorController2 to be able to iterate through several selected records in a listview and create attachments for each of them.
So, any suggestions? And thanks in advance for taking the time to look at this (sorry if my code is ugly or not well commented. I'll try to update the gist with some better comments soon!)
My goal is for my users to be able to look at a listview, select several records, and then click a button that will create pdfs from those records, attach them to the records, and then take the attachment and upload it to the Box folder associated with that record's parent.
I have uploaded all of my code to this gist: https://gist.github.com/AndersonKatharineTNC/fe722b94215efe76d7be7b0d807d9e5b
I have two major issues that I would like help solving:
1) Test_PdfGeneratorController errors out because the savePdf() method in PdfGeneratorController2 is a webservices method and it needs do do a mock webservices callout. I generated the wsdl2apex class for PdfGeneratorController2, and I created a test class called WebServiceMockImpl which does the mock response to the callout, but I can't figure out how to get the mock callout to happen in Test_PdfGeneratorController in order to cover the savePdf() method.
2) The Attach Monitoring PDF button currently only works as a detail page button. I'd like to update the code in PdfGeneratorController2 to be able to iterate through several selected records in a listview and create attachments for each of them.
So, any suggestions? And thanks in advance for taking the time to look at this (sorry if my code is ugly or not well commented. I'll try to update the gist with some better comments soon!)
As for the error, if the method is static, be sure to invoke it as such:
PdfGeneratorController2.savePdf( someId, someString );
It won't work as just:
savePdf( ... );
or
myController.savePdf( ... );
All Answers
<pre>
Test.SetMock( WebServiceMockImpl.class, new WebServiceMockImpl() );
</pre>
As for the error, if the method is static, be sure to invoke it as such:
PdfGeneratorController2.savePdf( someId, someString );
It won't work as just:
savePdf( ... );
or
myController.savePdf( ... );