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