function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Nelly78Nelly78 

TestClass for a webservice

Hi all hope you can help me!!
I have used the methods described in this post: https://developer.salesforce.com/forums/ForumsMain?id=906F00000008r4xIAA&language=en 
to create a custom PDF that attaches to the quote. Now I am stuck and dont know where to start to write a test class for the attachmentgenerator web service class below! Can anyone help?

global class AttachmentGeneratorCustomUK{
webService static String AttachPDFToQuote(string Id) {
        string retRes = '';
        try
        {
         PageReference pageRef = new PageReference('/apex/Quote_No_T_C_UK?Id='+Id);
         Blob content = pageRef.getContent();
         QuoteDocument doc = new QuoteDocument(Document = content, QuoteId = Id);
         insert doc;

         retRes='SUCCESS';
         return retRes;
       } catch(exception ex) {
           System.debug('--- Error ----------'+ ex);
           retRes= ex.getMessage();
           return retRes;
       }
   }
}
James LoghryJames Loghry
Testing an apex webservice method like yours is no different than testing any other class / method in Apex.  If you're talking callouts though, that's another story.  To test this method, you sould simply call AttachmentGeneratorCustomUK.AttachPDFToQuote() with various parameters, and assert that the return value is as expected.  Note, although you have a simple-ish method here, test all the boundary conditions, all the positiive, negative, exception scenarios you can think of, as external systems will depend on this functionality.