Can any one help me out with this Error .I'm getting
Visual force Error :Attempt to de-reference a null object
.
To identify the same product name in a table in a visual force page which is in a PDF format . I tried adding few lines in the code and it throws an Error .
Any help is very much appreciated.
Visual Force Code
<apex:page standardController="Quote"
applyHtmlTag="false" renderAs="PDF" showheader="false" applyBodyTag="false" extensions="QuoteContentController">
<div class="title"> <center> <h2>RFQ Information </h2> </center> </div>
<!-- <b>General Information </b> -->
<table cellspacing="0" cellpadding="0" width="100%" border="0" >
<tr>
<th bgcolor="Silver">General</th>
<th bgcolor="Silver">Information:</th>
<th bgcolor="Silver">Justification and Account </th>
<th bgcolor="Silver">Information:</th>
</tr>
<!-- </table>
<table border="0" cellpadding="0" cellspacing="0" width="100%">-->
<!-- <tr width="10%">
<td style="border-width: 0px; border-color:Black;border-style:solid;background-color:#FFFFFF;" align="left" width="10%">
<f style="color:Black; font-size:12px; font-family:Verdana;">
<td class="labelCol" >QuoteNumber:</td>
<td class="data2Col"><apex:outputText value="{!Quote.QuoteNumber}"/></td>
</f>
</td>-->
<tr>
<td ><f style="color:Black; font-size:12px; font-family:Verdana;">QuoteNumber:</f></td>
<td class="header-data"><apex:outputText value="{!Quote.QuoteNumber}"/></td>
<td ><f style="color:Black; font-size:12px; font-family:Verdana;">RFQ Justification:</f></td>
<td class="header-data"><apex:outputField value="{!Quote.Account.Name}"/></td>
</tr>
<tr>
<td> <f style="color:Black; font-size:12px; font-family:Verdana;">CustomerName: </f></td>
<td class="header-data"><apex:outputField value="{!Quote.Name}"/></td>
<td ><f style="color:Black; font-size:12px; font-family:Verdana;">Main Customers of Account:</f></td>
<td class="header-data"><apex:outputField value="{!Quote.Account.Main_Customers_of_Account__c}"/></td>
</tr>
<tr>
<td> <f style="color:Black; font-size:12px; font-family:Verdana;">Account Type:</f></td>
<td class="header-data"><apex:outputField value="{!Quote.Account.Recordtype.Name}"/></td>
<td ><f style="color:Black; font-size:12px; font-family:Verdana;">Bridgelux Competition at Account:</f></td>
<td class="header-data"><apex:outputField value="{!Quote.Account.Bridgelux_Competition_at_Account__c}"/></td>
</tr>
<tr>
<td> <f style="color:Black; font-size:12px; font-family:Verdana;">Date:</f></td>
<td class="header-data"><apex:outputField value="{!Quote.Effective_Date__c}"/></td>
<td ><f style="color:Black; font-size:12px; font-family:Verdana;">Geographic regions serviced:</f></td>
<td class="header-data"><apex:outputField value="{!Quote.Account.Servicing_Region__c}"/></td>
</tr>
<tr>
<td ><f style="color:Black; font-size:12px; font-family:Verdana;">Expected Order Date:</f></td>
<td class="header-data"><apex:outputField value="{!Quote.Effective_Date__c}"/></td>
<td ><f style="color:Black; font-size:12px; font-family:Verdana;">Annual lighting revenue:</f></td>
<td class="header-data"><apex:outputField value="{!Quote.Account.Annual_LED_Revenue__c}"/></td>
</tr>
<tr>
<td ><f style="color:Black; font-size:12px; font-family:Verdana;">Internal Comments:</f></td>
<td class="header-data"><apex:outputField value="{!Quote.Description}"/></td>
<td ><f style="color:Black; font-size:12px; font-family:Verdana;">Annual LED revenue or percent:</f></td>
<td class="header-data"><apex:outputField value="{!Quote.Account.Annual_LED_Revenue__c}"/></td>
</tr>
<tr>
<td ><f style="color:Black; font-size:12px; font-family:Verdana;">External Comments: </f></td>
<td class="header-data"><apex:outputField value="{!Quote.Comments__c}"/></td>
<td ><f style="color:Black; font-size:12px; font-family:Verdana;">Annual Purchases of LED Sources (SAM):</f></td>
<td class="header-data"><apex:outputField value="{!Quote.Account.Annual_Purchases_of_LED_Sources_SAM__c}"/></td>
</tr>
<tr>
<td ><f style="color:Black; font-size:12px; font-family:Verdana;">Probability(%):</f></td>
<td class="header-data"><apex:outputField value="{!Quote.Opportunity.Probability}"/></td>
<td ><f style="color:Black; font-size:12px; font-family:Verdana;">Percent of LED purchases that are COB:</f></td>
<td class="header-data"><apex:outputField value="{!Quote.Account.Percent_of_LED_purchases_that_are_COB__c}"/></td>
</tr>
<tr>
<td ><f style="color:Black; font-size:12px; font-family:Verdana;">Segment:</f></td>
<td class="header-data"><apex:outputField value="{!Quote.Opportunity.AccSegment__c}"/></td>
<td ><f style="color:Black; font-size:12px; font-family:Verdana;">Other Info:</f></td>
<td class="header-data"><apex:outputField value="{!Quote.Account.Percent_of_LED_purchases_that_are_COB__c}"/></td>
</tr>
<tr>
<td ><f style="color:Black; font-size:12px; font-family:Verdana;">Application:</f></td>
<td class="header-data"><apex:outputField value="{!Quote.Opportunity.AccApplication__c}"/></td>
</tr>
<tr>
<td ><f style="color:Black; font-size:12px; font-family:Verdana;">Persona:</f></td>
<td class="header-data"><apex:outputField value="{!Quote.Opportunity.Persona__c}"/></td>
</tr>
<tr>
<td ><f style="color:Black; font-size:12px; font-family:Verdana;">Geography:</f></td>
<td class="header-data"><apex:outputField value="{!Quote.Opportunity.Region__c}"/></td>
</tr>
<!-- <tr>
<td ><f style="color:Black; font-size:12px; font-family:Verdana;">Opportunity RecordType:</f></td>
<td class="header-data"><apex:outputField value="{!Quote.Opportunity.RecordType.Name}"/></td>
</tr> -->
</table>
<h3>QuotelineItems Details</h3>
<table class="bordered">
<thead>
<tr>
<!-- <td bgcolor="Silver" class="header-table-heading">Part</td> -->
<td class="header-table-heading" bgcolor="#C0C0C0">PartNumbers</td>
<td class="header-table-heading" bgcolor="#C0C0C0">Price</td>
<td class="header-table-heading" bgcolor="#C0C0C0">EndCustomerPrice</td>
<td class="header-table-heading" bgcolor="#C0C0C0">Quantity</td>
<td class="header-table-heading" bgcolor="#C0C0C0">Total</td>
</tr>
</thead>
<tbody>
<apex:repeat value="{!Quote.QuotelineItems}" var="qli">
<tr>
<td class="header-table-data" ><apex:outputText value="{!qli.Product2.Name}"/></td>
<td class="header-table-data" ><apex:outputText value="{!qli.Unitprice}"/></td>
<td class="header-table-data"><apex:outputField value="{!qli.End_Customer_Price__c}"/></td>
<td class="header-table-data"><apex:outputField value="{!qli.Quantity}"/></td>
<td class="header-table-data"><apex:outputField value="{!qli.TotalPrice}"/></td>
</tr>
</apex:repeat>
</tbody>
</table>
<h3>Competitive Data</h3>
<table class="bordered">
<thead>
<tr>
<td class="header-table-heading" bgcolor="#C0C0C0">Company</td>
<td class="header-table-heading" bgcolor="#C0C0C0">Product Series</td>
<td class="header-table-heading" bgcolor="#C0C0C0">Part Numbers</td>
<td class="header-table-heading" bgcolor="#C0C0C0">Price</td>
<td class="header-table-heading" bgcolor="#C0C0C0">volume</td>
<td class="header-table-heading" bgcolor="#C0C0C0">Date Price is Valid</td>
</tr>
</thead>
<tbody>
<apex:repeat value="{!Quote.Competitor_s__r}" var="com">
<tr>
<td class="header-table-data"><apex:outputText value="{!com.Name}"/></td>
<td class="header-table-data"><apex:outputText value="{!com.Product_Series__c}"/></td>
<td class="header-table-data"><apex:outputField value="{!com.Part_Number__c }"/></td>
<td class="header-table-data"><apex:outputField value="{!com.Price_Offered__c}"/></td>
<td class="header-table-data"><apex:outputField value="{!com.Volume__c}"/></td>
<td class="header-table-data"><apex:outputField value="{!com.Date_Price_is_Valid__c}"/></td>
</tr>
</apex:repeat>
</tbody>
</table>
<h3>OpportunityForecast Details</h3>
<table class="bordered">
<thead>
<tr>
<td class="header-table-heading" bgcolor="#C0C0C0" colspan="3" ></td>
<td class="header-table-heading" bgcolor="#C0C0C0" colspan="5" >FORECAST DATE</td>
</tr>
<tr>
<td class="header-table-heading" bgcolor="#C0C0C0">Opportunity Name</td>
<td class="header-table-heading" bgcolor="#C0C0C0">PartNumbers</td>
<td class="header-table-heading" bgcolor="#C0C0C0"></td>
<td class="header-table-heading" bgcolor="#C0C0C0">Q1 2014 </td>
<td class="header-table-heading" bgcolor="#C0C0C0">Q2 2014 </td>
<td class="header-table-heading" bgcolor="#C0C0C0">Q3 2014 </td>
<td class="header-table-heading" bgcolor="#C0C0C0">Q4 2014 </td>
<!--<td class="header-table-heading" bgcolor="#C0C0C0">Quantity</td>
<td class="header-table-heading" bgcolor="#C0C0C0">Price</td>
<td class="header-table-heading" bgcolor="#C0C0C0">Amount</td>
<td class="header-table-heading" bgcolor="#C0C0C0">Quarter</td>
<td class="header-table-heading" bgcolor="#C0C0C0">Month</td>
<td class="header-table-heading" bgcolor="#C0C0C0">Actual Price</td>
<td class="header-table-heading" bgcolor="#C0C0C0">Year</td>
<td class="header-table-heading" bgcolor="#C0C0C0">Date</td>-->
<td class="header-table-heading" bgcolor="#C0C0C0">MonthText</td>
<!-- <td class="header-table-heading" bgcolor="#C0C0C0">ForecastDate</td>
<td class="header-table-heading" bgcolor="#C0C0C0">ForecastName</td>-->
<td rowspan="0" class="header-table-heading">Grand<br/>Total </td>
</tr>
</thead>
<tbody>
<apex:repeat value="{!disp_list}" var="opf">
<tr>
<td class="header-table-data"><apex:outputText value="{!opf.gmod_Opportunity}"/></td>
<td class="header-table-data"><apex:outputText value="{!opf.gmod_Product}"/></td>
<td class="header-table-data" >Forecast Qty<br/>ForecastAmt<br/></td>
<td class="header-table-data"><apex:outputText value="{!opf.gmod_Quantity}"/><br/><apex:outputText value="{!opf.gmod_Amount }"/><br/></td>
<td class="header-table-data"><apex:outputText value="{!opf.gmod_Quantity}"/><br/><apex:outputText value="{!opf.gmod_Amount }"/><br/></td>
<td class="header-table-data"><apex:outputText value="{!opf.gmod_Quantity}"/><br/><apex:outputText value="{!opf.gmod_Amount }"/><br/></td>
<td class="header-table-data"><apex:outputText value="{!opf.gmod_Quantity}"/><br/><apex:outputText value="{!opf.gmod_Amount }"/><br/></td>
<!--<td class="header-table-data"><apex:outputText value="{!opf.gmod_Quantity }"/></td>
<td class="header-table-data"><apex:outputText value="{!opf.gmod_Price }"/></td>
<td class="header-table-data"><apex:outputText value="{!opf.gmod_Amount }"/></td>
<td class="header-table-data"><apex:outputText value="{!opf.gmod_Quarter }"/></td>
<td class="header-table-data"><apex:outputText value="{!opf.gmod_Month }"/></td>
<td class="header-table-data"><apex:outputText value="{!opf.Actual_Price }"/></td>
<td class="header-table-data"><apex:outputText value="{!opf.gmod_Year }"/></td>
<td class="header-table-data"><apex:outputText value="{!opf.gmod_date }"/></td> -->
<td class="header-table-data"><apex:outputText value="{!opf.gmod_Month_Text }"/></td>
<!--<td class="header-table-data"><apex:outputText value="{!opf.Forecast_Date }"/></td>
<td class="header-table-data"><apex:outputText value="{!opf.Name }"/></td>-->
<td rowspan="1" style="text-align:left" align="right" class="header-table-heading"> {!subtotalofquantity }<br/>
{!subtotalofAmount }<br/></td>
</tr>
</apex:repeat>
</tbody>
<tfoot>
<tr class="foot">
<!--<td align="right" colspan="2" width="10%" class="header-table-heading">
Subtotal:
</td>
<td align="right" colspan="2" width="100%" class="header-table-heading">
Grandtotal:
</td>
<td align="right" width="12%" class="subtotal">
<apex:OutputText value="{!opf.gmod_Quantity__c}"/>
</td>-->
<tr>
<td colspan="2" style="text-align:left" align="right" class="header-table-data">SubTotal :</td>
<td colspan="0" style="text-align:left" align="right" class="header-table-data" >Forecast Qty<br/>ForecastAmt<br/> </td>
<td colspan="1" style="text-align:left" align="right" class="header-table-data"> {!subtotalofquantity}<br/>
{!subtotalofAmount}<br/></td>
<td colspan="1" style="text-align:left" align="right" class="header-table-data"> {!subtotalofquantity }<br/>
{!subtotalofAmount }<br/></td>
<td colspan="1" style="text-align:left" align="right" class="header-table-data"> {!subtotalofquantity }<br/>
{!subtotalofAmount }<br/></td>
<td colspan="1" style="text-align:left" align="right" class="header-table-data"> {!subtotalofquantity }<br/>
{!subtotalofAmount }<br/></td>
</tr>
<tr>
<td colspan="2" style="text-align:left" align="right" class="header-table-heading">GrandTotal</td>
<td colspan="0" style="text-align:left" align="right" class="header-table-heading" >Forecast Qty<br/>ForecastAmt<br/> </td>
<td colspan="1" style="text-align:left" align="right" class="header-table-heading"> {!subtotalofquantity }<br/>
{!subtotalofAmount }<br/></td>
<td colspan="1" style="text-align:left" align="right" class="header-table-heading"> {!subtotalofquantity }<br/>
{!subtotalofAmount }<br/></td>
<td colspan="1" style="text-align:left" align="right" class="header-table-heading"> {!subtotalofquantity }<br/>
{!subtotalofAmount }<br/></td>
<td colspan="1" style="text-align:left" align="right" class="header-table-heading"> {!subtotalofquantity }<br/>
{!subtotalofAmount }<br/></td>
</tr>
</tr>
</tfoot>
</table>
</apex:page>
Apex Code :
public with sharing class QuoteContentController {
public Competitor__c com{get;set;}
public gmod__Opportunity_Forecast__c opflist{get;set;}
public Id qId {get;set;}
Public string all{get;set;}
//Declare a wrapper class
public class Wrapperclass{
//custom wrapper datatype
Public string Name{get;set;}
Public string AccountType{get;set;}
Public date todaysDate{get;set;}
Public date Expected_Order_Date{get;set;}
Public string Probability{get;set;}
Public string Internal_Comment{get;set;}
Public string External_Comment{get;set;}
Public string Segment{get;set;}
Public string Application{get;set;}
Public string Persona{get;set;}
Public string Geogrpahy{get;set;}
Public string PartNumbers{get;set;}
Public Decimal Price{get;set;}
Public Decimal End_Customer_Price{get;set;}
Public Decimal Quantity {get;set;}
Public Decimal Total{get;set;}
Public string RFQ_justification{get;set;}
Public string Main_Customer_of_Account{get;set;}
Public string Bridgelux_competition_at_account{get;set;}
Public string Geographic_regions_serviced{get;set;}
Public string Annual_lighting_revenue{get;set;}
Public string Annual_LED_revenue_or_percent{get;set;}
Public string Annual_purchases_of_LED_light_sources{get;set;}
Public string Percent_of_LED_purchases_that_are_COB{get;set;}
Public string Other_information{get;set;}
Public string Product_Series{get;set;}
Public string Volume{get;set;}
Public string Date_Price_is_Valid{get;set;}
Public string gmod_Opportunity{get;set;}
Public string gmod_Product{get;set;}
Public Decimal gmod_Quantity{get;set;}
Public Decimal gmod_Price{get;set;}
Public Decimal gmod_Quarter{get;set;}
Public Decimal gmod_Month{get;set;}
Public Decimal gmod_Amount{get;set;}
Public Decimal Actual_Price{get;set;}
Public Decimal gmod_Year{get;set;}
Public Date gmod_date{get;set;}
Public string gmod_Month_Text{get;set;}
Public Date Forecast_Date{get;set;}
Public wrapperClass(){}
}
Public QuoteContentController(){}
Public QuoteContentController(ApexPages.StandardController controller) {
qId=Apexpages.currentPage().getparameters().get('Id');
disp_Map = new Map<String,wrapperClass>();
}
Public Integer subtotalofquantity{get;set;}
Public Integer subtotalofamount{get;set;}
public Map<String,wrapperClass> disp_Map{get;set;}
Public List<wrapperClass> disp_list {get;set;}{
//subtotalofquantity=0;
// subtotalofamount=0;
// Public List<wrapperClass> disp_list(){
//define constructor to instantiate the wrapper data type
disp_list=new list<wrapperclass>();
//Query all the list
list<Quote> q =[select id ,Name ,QuoteNumber,Effective_Date__c ,Comments__c ,Quote.Opportunity.id,
Quote.Opportunity.Probability ,Quote.Opportunity.AccSegment__c ,Quote.Opportunity.AccApplication__c,Quote.Opportunity.Persona__c,Quote.Opportunity.Region__c
from Quote where id=:apexpages.currentpage().getparameters().get('id')];
// list<QuoteLineItem> qli =[Select QuoteId , PricebookEntry.Product2.Name ,Unitprice ,End_Customer_Price__c ,Quantity , TotalPrice from QuoteLineItem where QuoteId =:qId ];
// list<Account> a = [Select id ,Name ,Main_Customers_of_Account__c ,Bridgelux_Competition_at_Account__c,Servicing_Region__c ,
// Annual_LED_Revenue__c,Annual_Purchases_of_LED_Sources_SAM__c ,Percent_of_LED_purchases_that_are_COB__c from Account where account.id =:qId ];
// list<Competitor__c> com = [Select id ,Part_Number__c,Product_Series__c,Price_Offered__c,Volume__c,Date_Price_is_Valid__c from Competitor__c ] ;
Opportunity opp =[select id , Name, (select id, Quantity, product2id from OpportunityLineItems), probability, AccSegment__c from Opportunity where opportunity.Id =:q[0].opportunity.id];
list<gmod__Opportunity_Forecast__c> opflist = [Select id ,Name ,gmod__opportunity__r.id,gmod__Product__c,gmod__Quantity__c,gmod__Price__c , gmod__Month__c, gmod__date__c, gmod__Quarter__c ,gmod__Amount__c ,Actual_Price__c ,gmod__Year__c ,gmod__Month_Text__c ,Forecast_Date__c,gmod__Product__r.Name ,gmod__opportunity__r.name from gmod__Opportunity_Forecast__c WHERE gmod__Product__c!=null and gmod__opportunity__r.id =:opp.id order by gmod__Month__c asc limit 9];
// list<gmod__Opportunity_Forecast__c> opflist=[ SELECT id,gmod__product__r.name,gmod__Quantity__c,createdby.name , gmod__opportunity__r.name ,gmod__Amount__c,GROUPING(gmod__Quantity__c) grpQty, GROUPING(gmod__Amount__c) grpAmt ,COUNT(id) oppfc from gmod__Opportunity_Forecast__c GROUP BY CUBE(gmod__Quantity__c, gmod__Amount__c) ORDER BY GROUPING(gmod__Quantity__c), GROUPING(gmod__Amount__c) ];
// Executes in DC
// [SELECT gmod__product__r.name ,gmod__opportunity__c,COUNT(id) cnt FROM gmod__Opportunity_Forecast__c WHERE gmod__Product__c!=null GROUP BY gmod__product__r.name ,gmod__opportunity__c];
//Executes in DC
/*list<AggregateResult> groupedResults =[SELECT gmod__product__r.name ,gmod__opportunity__c,sum(gmod__Price__c) gmod__Price__c ,SUm(gmod__Amount__c) gmod__Amount__c,Sum(gmod__Quantity__c) gmod__Qunatity__c,COUNT(id) Quantity FROM gmod__Opportunity_Forecast__c WHERE gmod__date__c=THIS_FISCAL_YEAR GROUP BY gmod__product__r.name ,gmod__opportunity__c];
for (AggregateResult ar : groupedResults) {
// System.debug('Campaign ID' + ar.get('CampaignId'));
System.debug('sum amount' + ar.get('gmod__Amount__c'));
System.debug('Count' + ar.get('Quantity'));
// System.debug('Sum Quantity' + ar.get('gmod__Quantity__c'));
}*/
//Iterate through each list to extract the values and add it to the custom wrapper data type
for (Quote qt :q){
System.debug('Quote Size ++ '+q.size());
System.debug('opp forcast ++ ' +opflist.size());
for(integer i=0;i<opflist.size();i++){
subtotalofquantity+= integer.valueOf(opflist[i].gmod__Quantity__c);
subtotalofamount+= integer.valueOf(opflist[i]. gmod__Amount__c);
//Instantiating the wrapper SObject
wrapperclass w = new wrapperclass();
if(disp_Map.containsKey(opflist[i].gmod__Product__r.Name)!= disp_Map.containsKey(opflist[i-1].gmod__Product__r.Name)){
if(opflist[i].gmod__Product__r.Name != opflist[i-1].gmod__Product__r.Name ){
if(disp_Map.containsKey(opflist[i].gmod__Product__r.Name )){
w = disp_Map.get(opflist[i].gmod__Product__r.Name);
w.gmod_Quantity =disp_Map.get(opflist[i].gmod__Product__r.Name).gmod_Quantity + opflist[i].gmod__Quantity__c;
w.gmod_Amount = disp_Map.get(opflist[i].gmod__Product__r.Name).gmod_Amount + opflist[i].gmod__Amount__c;
} else {
w.gmod_Quantity =opflist[i].gmod__Quantity__c;
w.gmod_Amount=opflist[i]. gmod__Amount__c;
}
}
//Assigning the wrapper variables from the SObject Fields in the database.
w.gmod_Opportunity = opflist[i].gmod__Opportunity__r.Name;
w.gmod_Product = opflist[i].gmod__Product__r.Name;
w.gmod_Quantity =opflist[i].gmod__Quantity__c;
w.gmod_Price=opflist[i].gmod__Price__c;
w.Name =opflist[i].Name;
w.gmod_Quarter=opflist[i].gmod__Quarter__c;
w.gmod_Month=opflist[i].gmod__Month__c;
w.gmod_Amount=opflist[i]. gmod__Amount__c;
w.Actual_Price=opflist[i].Actual_Price__c;
w.gmod_Year=opflist[i].gmod__Year__c;
w.gmod_date=opflist[i].gmod__date__c;
w.gmod_Month_Text=opflist[i].gmod__Month_Text__c;
w.Forecast_Date=opflist[i].Forecast_Date__c;
disp_Map.put(opflist[i].gmod__Product__r.Name,w);
//Adding everthing to the List
// w.name =qt.name;
// disp_list.add(w);
// return disp_list;
}
}
for(wrapperclass w : disp_Map.values()){
disp_list.add(w);
}
}
}
} //End of Class