• Thomas Kayser-Eichberg
  • NEWBIE
  • 0 Points
  • Member since 2019

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 3
    Replies
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;
    }


}


 
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;
    }


}


 
Hi All,

Can you plz help me on covering the below two lines of attachment for below class. Current code coverage is 86%. Need to get 100%. Thanks
 
User-added image


Test class:

@isTest
public class CaseCreationWithQAttachment_Test {
    static testMethod void test1()
    {
        Case cs = new Case(Subject = 'Test', Origin = 'Phone', Status = 'New');
        insert cs;
        
        Attachment attach=new Attachment();       
        attach.Name='Unit Test Attachment';
        Blob bodyBlob=Blob.valueOf('Unit Test Attachment Body');
        attach.body=bodyBlob;
        attach.parentId=cs.id;
        insert attach;
        
        List<Attachment> attachments=[select id, name from Attachment where parent.id=:cs.id];
        System.assertEquals(1, attachments.size());
        
        ApexPages.StandardController stdCtr = new ApexPages.StandardController(cs);
        CaseCreationWithQAttachment ctr = new CaseCreationWithQAttachment(stdCtr);
        ctr.caseData = cs;
        ctr.attachData = attach;
        ctr.customSave();   
    }
}