0

Class

public with sharing class CreateQuotePDFController {
    public list<QuoteLineItem> quoteLineItemsList{get;set;}
    public Id getid{get;set;} 
    public Double grandTotalTax{get;set;}
    public Double finalPO{get;set;}
    public Date expirationDate{get;set;}
    public CreateQuotePDFController(ApexPages.StandardController controller) {
        getid=ApexPages.currentPage().getParameters().get('id');
        Quote quote = [SELECT Account.Name, Account.BillingCountry,Account.BillingPostalCode,Account.BillingState,Account.BillingCity,Account.BillingStreet, Contact.Name, GrandTotal, ExpirationDate FROM quote where id=:getid ];
        quoteLineItemsList = [select id,product2id,Discount_Percentage__c, PricebookEntry.Product2.Name , UnitPrice, Quantity, Subtotal from quotelineitem where QuoteId=: getid];        
        System.debug('grand total is : ' +quote.GrandTotal);
        grandTotalTax = (quote.GrandTotal * 0.18).setScale(2);
        finalPO = (quote.GrandTotal+grandTotalTax).setScale(2);
        expirationDate = quote.ExpirationDate;
    }
}

I tried the below code but its not working

Test

@isTest
public class CreateQuotePDFController_Test {
@testsetup static void data_setup(){
Account acc1 = new Account();
        acc1.Name = 'test account';
        insert acc1;
        system.debug('insert acc1 is success');

        Opportunity Opp1 = new Opportunity();
        Opp1.Name = 'testOpp';
        Opp1.AccountId = acc1.Id;
        Opp1.StageName = 'Closed Won';
        Opp1.CloseDate = system.Today();
        insert Opp1;        
        system.debug('insert opp1 success');

        Product2 Pro1 = new Product2();
        Pro1.Name = 'SLA: Bronze';
        pro1.isActive = True;
        Insert pro1;
        system.debug('insert pro1 is success');        

        Pricebook2 pb = new pricebook2();
        pb.Name = 'Standard Price Book 2009';
        pb.description = 'Price Book 2009 Products';
        pb.isActive = True;
        insert pb;
        system.debug('pb value is'+ pb.Id);
        system.debug('insert pricebook2 is success');

        Id pricebookId = Test.getStandardPricebookId();        

        PricebookEntry StandardPriceBookEntry = new PricebookEntry();
        StandardPriceBookEntry.Pricebook2Id = pricebookId;
        StandardPriceBookEntry.Product2Id = pro1.Id;
        StandardPriceBookEntry.UnitPrice = 10000;
        StandardPriceBookEntry.IsActive =True;        
        insert StandardPriceBookEntry;
        system.debug('insert StandardPriceBookEntry');

        PricebookEntry pbe = new PricebookEntry(pricebook2id=pb.id, product2id=pro1.id, unitprice=10000, isActive = True);
        insert pbe;
        system.debug('insert pbe is success');

        Quote Quo1 = new Quote(); 
        Quo1.OpportunityId = Opp1.Id;
        Quo1.Pricebook2Id = pb.Id;
        Quo1.Name = 'test Quo1';      
        insert Quo1;       
        system.debug('insert Quo1 success');

        QuoteLineItem QLI  = new QuoteLineItem();
        QLI.Product2Id = pro1.Id;
        QLI.QuoteId = Quo1.Id;
        QLI.PricebookEntryId = Pbe.Id;
        QLI.Quantity = 2;
        QLI.UnitPrice = 150000.0; 
        insert QLI;    
        system.debug('insert QLI is success');

    PageReference testPage = Page.CreateQuotePDF; 
       Test.setCurrentPage(testPage);
       testPage.getParameters().put('Id', String.valueOf(Quo1.Id));
        
       ApexPages.StandardController sc = new  ApexPages.StandardController(Quo1);     
       CreateQuotePDFController ext = new CreateQuotePDFController(sc);         
         System.debug(ext.quoteLineItemsList());
        Quote quote = [SELECT Account.Name, Account.BillingCountry,Account.BillingPostalCode,Account.BillingState,Account.BillingCity,Account.BillingStreet, Contact.Name, GrandTotal, ExpirationDate FROM quote where id=:Quo1.Id ];
       QuoteLineItem quoteLineItemsList = [select id,product2id,Discount_Percentage__c, PricebookEntry.Product2.Name , UnitPrice, Quantity, Subtotal from quotelineitem where QuoteId=:Quo1.Id];
   }    
}
3
  • I tried the below code but its not working Commented Oct 8, 2021 at 6:10
  • 1
    What does "not working" mean? This site thrives on details. If you're getting an error message somewhere, you should include the entire error message in your question (don't try to paraphrase it) and help us by pointing out which line the error occurs on. edit your question to add that information.
    – Derek F
    Commented Oct 8, 2021 at 11:19
  • From Below Line i am unable to add my test class, i just tried in that way, but i am unable to do code coverage. PageReference testPage = Page.CreateQuotePDF; Test.setCurrentPage(testPage); testPage.getParameters().put('Id', String.valueOf(Quo1.Id)); ApexPages.StandardController sc = new ApexPages.StandardController(Quo1); CreateQuotePDFController ext = new CreateQuotePDFController(sc); System.debug(ext.quoteLineItemsList()); Commented Oct 8, 2021 at 13:59

1 Answer 1

0

@isTest public class CreateQuotePDFController_Test { @testsetup static void data_setup(){ Account acc1 = new Account(); acc1.Name = 'test account'; insert acc1; system.debug('insert acc1 is success');

    Opportunity Opp1 = new Opportunity();
    Opp1.Name = 'testOpp';
    Opp1.AccountId = acc1.Id;
    Opp1.StageName = 'Closed Won';
    Opp1.CloseDate = system.Today();
    insert Opp1;        
    system.debug('insert opp1 success');

    Product2 Pro1 = new Product2();
    Pro1.Name = 'SLA: Bronze';
    pro1.isActive = True;
    Insert pro1;
    system.debug('insert pro1 is success');        

    Pricebook2 pb = new pricebook2();
    pb.Name = 'Standard Price Book 2009';
    pb.description = 'Price Book 2009 Products';
    pb.isActive = True;
    insert pb;
    system.debug('pb value is'+ pb.Id);
    system.debug('insert pricebook2 is success');

    Id pricebookId = Test.getStandardPricebookId();        

    PricebookEntry StandardPriceBookEntry = new PricebookEntry();
    StandardPriceBookEntry.Pricebook2Id = pricebookId;
    StandardPriceBookEntry.Product2Id = pro1.Id;
    StandardPriceBookEntry.UnitPrice = 10000;
    StandardPriceBookEntry.IsActive =True;        
    insert StandardPriceBookEntry;
    system.debug('insert StandardPriceBookEntry');

    PricebookEntry pbe = new PricebookEntry(pricebook2id=pb.id, product2id=pro1.id, unitprice=10000, isActive = True);
    insert pbe;
    system.debug('insert pbe is success');

    Quote Quo1 = new Quote(); 
    Quo1.OpportunityId = Opp1.Id;
    Quo1.Pricebook2Id = pb.Id;
    Quo1.Name = 'test Quo1';      
    insert Quo1;       
    system.debug('insert Quo1 success');

    QuoteLineItem QLI  = new QuoteLineItem();
    QLI.Product2Id = pro1.Id;
    QLI.QuoteId = Quo1.Id;
    QLI.PricebookEntryId = Pbe.Id;
    QLI.Quantity = 2;
    QLI.UnitPrice = 150000.0; 
    insert QLI;    
    system.debug('insert QLI is success');

PageReference testPage = Page.CreateQuotePDF; 
   Test.setCurrentPage(testPage);
   testPage.getParameters().put('Id', String.valueOf(Quo1.Id));
    
   ApexPages.StandardController sc = new  ApexPages.StandardController(Quo1);     
   CreateQuotePDFController ext = new CreateQuotePDFController(sc);         
     System.debug(ext.quoteLineItemsList());
    Quote quote = [SELECT Account.Name, Account.BillingCountry,Account.BillingPostalCode,Account.BillingState,Account.BillingCity,Account.BillingStreet, Contact.Name, GrandTotal, ExpirationDate FROM quote where id=:Quo1.Id ];
   QuoteLineItem quoteLineItemsList = [select id,product2id,Discount_Percentage__c, PricebookEntry.Product2.Name , UnitPrice, Quantity, Subtotal from quotelineitem where QuoteId=:Quo1.Id];

}

}

2
  • Welcome to SFSE. It is unclear if you intended this to be an answer or an edit to your question. Please take a moment to read How to Ask, How to Answer, and help center to get a better sense of our format as a community. Thanks!
    – David Reed
    Commented Oct 8, 2021 at 14:20
  • SFSE generally does not encourage answers that consist solely of code: we look for explanation of a specific problem, as we're not a site for code sharing per se.
    – David Reed
    Commented Oct 8, 2021 at 14:20

Not the answer you're looking for? Browse other questions tagged .