You need to sign in to do that
Don't have an account?
Attempt to de-reference a null object
Hello Friend I am getting the error of attemt to de-reference a null object.I am trying to giving product in quote line item
public class CLS_NewQuoteLineItems {
public string surl='';
public string pricebookentry {get;set;}
public string name{get;set;}
public id qid{get;set;}
public boolean b{get;set;}
public boolean b1{get;set;}
public boolean b2{get;set;}
public List<WrapperProduct> prodlist ;
public List<WrapperProduct> selectprodlist {get;set;}
public list<product2> plist{get;set;}
public list<product2> plists{get;set;}
public quote q;
public list<Quotelineitem> qlist{get;set;}
public CLS_NewQuoteLineItems(){
b1=false;
qlist=new list<Quotelineitem>();
surl = ApexPages.currentPage().getUrl();
if(surl.contains('0Q0'))
{
q=new quote();
qid=ApexPages.currentPage().getParameters().get('id');
q=[select name,Pricebook2Id from quote where id=:qid];
name=q.name;
}
if(q.Pricebook2id==null)
{
b2=true;
b=false;
}
else
{
b=true;
b2=false;
}
plist=new list<product2>();
prodlist=new List<WrapperProduct>();
selectprodlist=new List<WrapperProduct>();
plist=[select name,ProductCode ,Family,Description from product2];
system.debug('ppppppppppppp'+plist);
}
public List<WrapperProduct> getprodlist () {
integer i = 0;
for(product2 p: plist)
{
WrapperProduct lw = new WrapperProduct(p);
prodlist.add(lw);
i++;
}
system.debug('222222222222'+prodlist);
return prodlist;
}
public pageReference selectproduct()
{
b=false;
b1=true;
b2=false;
plists=new list<product2>();
for (WrapperProduct wp : prodlist)
{
if (wp.checked)
{
plists.add(wp.pro);
selectprodlist.add(wp);
}
}
System.debug('@@@@@selected product@@@@@@@'+ selectprodlist);
return null;
}
public pageReference CancelRec()
{
pagereference pr = new pagereference('/apex/VF_QuoteDetailPage?id='+qid);
return pr;
}
public void savepricebook()
{
b2=false;
b=true;
b1=false;
Pricebook2 prc=new Pricebook2();
system.debug('ppppppricebookpppppppp'+pricebookentry);
prc=[select id,Name from Pricebook2 where name=:pricebookentry];
system.debug('ppppppppppppp'+plist);
if(q.Pricebook2Id==null)
{
q.Pricebook2Id=prc.id;
update q;
}
system.debug('aaaaaaaaaaaa'+plist);
system.debug('WWWWWaupdatedquoteaaa'+q);
}
public pageReference insertQuoteItem()
{
System.debug('@@@@@selected product@@@on insertion@@@@'+ selectprodlist);
pricebookentry pEntry = new pricebookentry();
pEntry=[select Id,Pricebook2Id from PricebookEntry where Pricebook2Id=:q.Pricebook2Id limit 1];
product2 pronew=new product2();
for(WrapperProduct p:selectprodlist)
{
Quotelineitem qa=new Quotelineitem();
qa.pricebookentryId= pEntry.id;
qa.pricebookentry.product2id=p.prodid;***********//For this line i am getting the error.
qa.UnitPrice=p.salesprice;
qa.QuoteId=qid;
qa.Quantity=p.Quan;
qa.Description=p.LineItemDescription;
qlist.add(qa);
}
System.debug('uuuuuuuuuuuuuuu'+ qlist);
System.debug('u4444444444444444'+ selectprodlist);
insert qlist;
System.debug('iiiiiiiiiiiii'+qlist);
pagereference pr = new pagereference('/apex/VF_QuoteDetailPage?id='+qid);
return pr;
//return null;
}
public class WrapperProduct
{
public boolean checked {get;set;}
public string productName{get;set;}
public string productcode{get;set;}
public Decimal listprice{get;set;}
public string productdescription{get;set;}
public string productfamily{get;set;}
public id prodid{get;set;}
public product2 pro{get;set;}
public Integer Quan{get;set;}
public Integer Discount{get;set;}
public String LineItemDescription{get;set;}
public Decimal salesprice{get;set;}
public WrapperProduct()
{
checked = false;
}
public WrapperProduct(product2 p)
{
// pro=p;
prodid=p.id;
productName =p.name;
productcode=p.ProductCode;
productdescription=p.Description;
productfamily = p.Family;
}
}
}
how can i remove this
Hello,
Can you please post your stacktrace here so we can see exactly the error? On which action does the error occur?
Happy Friday,
Adrian
Hi
@Adrian,
I am getting this one
System.NullPointerException: Attempt to de-reference a null object
Error is in expression '{!insertQuoteItem}' in component <apex:page> in page vf_newquotelineitems
Class.CLS_NewQuoteLineItems.insertQuoteItem: line 128, column 1
Hmmm, the error is around there, the PricebookEntry, or Product or Quote related...
Check to see the values for "pEntry=[select Id,Pricebook2Id from PricebookEntry where Pricebook2Id=:q.Pricebook2Id limit 1];" and also for p inside that for.
Why are you assigning "qa.pricebookentry.product2id=p.prodid;" ?
I don't think you can modify the Product2Id of a PBE after creation.
PS: nice debugs! :)
Adrian