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
Behzad Bahadori 18Behzad Bahadori 18 

How do I write a test class for this

How Do I make a test case for this 
public String ourl {get;set;}
	public String url {get;set;} 
	Blob content;
	public NewPdfQuote() {

		url = ApexPages.currentPage().getParameters().get('qotId');
		generateNewQuotePDF();

	}

	     public  QuoteDocument generateNewQuotePDF(){
          
        ourl = '/apex/QuotePDF?id=' + url ;

        System.debug('ourl   ' + ourl);

        PageReference pr = Page.QuotePDF;
        pr.getParameters().put('id', url);

        System.debug('saveQuote() Quote: ' + url);

        if (!Test.isRunningTest())
            content = pr.getContentAsPDF();
        else
            content = Blob.valueOf('Unit Test Attachment Body');

       
         //emailURL = '/_ui/core/email/author/EmailAuthor?p3_lkid=' + urlId + '&doc_id=' + record.Id + '&retURL=%2F' + urlId ;
        return NULL;
  
    }

    	 public PageReference sendQuote()
   			 {
				     QuoteDocument doc1 = new QuoteDocument(Document = content, QuoteId = url);

				       // Database.SaveResult insertResult = Database.Insert(doc, false);
				        insert doc1;
				        return NULL;
		}

 
Bhaswanthnaga vivek vutukuriBhaswanthnaga vivek vutukuri
@isTest
Private class testnewPdfquote
{
    static testMethod void testNewQuotePDF()
    {
        quote q= new quote();
        q.name ='dsaf'; ...... insert q;

        PageReference tpageRef = Page.NameOfYourPageHere;
        Test.setCurrentPage(tpageRef);

        ApexPages.currentPage().getParameters().put('Id', q.Id);
        Test.StartTest();
        NewPdfQuote n= new NewPdfQuote();
        n.generateNewQuotePDF();
        n.sendQuote();
        Test.StopTest();

    }
}

 
Behzad Bahadori 18Behzad Bahadori 18
Thank you, but now I get the error System.DmlException: Insert failed. First exception on row 0; first error: INSUFFICIENT_ACCESS_ON_CROSS_REFERENCE_ENTITY, insufficient access rights on cross-reference id: []