You need to sign in to do that
Don't have an account?
System.NullPointerException: Attempt to de-reference a null object??
Hi All
System.NullPointerException: Attempt to de-reference a null object
Class.FConnect.SelectedProductsunderservice.Add: line 78, column 1
<apex:page controller="SelectedProductsunderservice">
<apex:form >
<apex:pageBlock >
<apex:pageBlockButtons id="id">
<apex:commandButton value=" Add " action="{!Add}" reRender="id"/>
<apex:commandButton value="Cancel" action="{!cancel}" reRender="id"/>
</apex:pageBlockButtons>
<apex:pageMessages ></apex:pageMessages>
<apex:pageBlockTable value="{!ProductsUnderService}" var="ip" id="table">
<apex:column >
<apex:inputCheckbox value="{!ip.selected}"/>
</apex:column>
<apex:column value="{!ip.con.Name}"/>
<apex:column value="{!ip.con.Products__c}"/>
<apex:column value="{!ip.con.Description__c}"/>
<apex:column value="{!ip.con.Serial_ID__c}"/>
<apex:column value="{!ip.con.Asset_Tag__c}"/>
<apex:column value="{!ip.con.Quantity__c}"/>
<apex:column value="{!ip.con.Customer__c}"/>
</apex:pageBlockTable>
</apex:pageBlock>
</apex:form>
</apex:page>
public with sharing class SelectedProductsunderservice
{
public String AgreementLineId;
public String Customer;
public String customerName;
Public List<Products__c> Products;
Public List<Product__c> customProducts;
public List<ProductsUnderService> ProductsUnderServiceList{get;set;}
List<Id> proIds = new List<Id>();
List<Id> iprodIds = new List<Id>();
public SelectedProductsunderservice ()
{
customProducts = new List<Product__c>();
AgreementLineId=apexpages.currentpage().getparameters().get('Agreement_Line');
Agreement_Line__c al=[select id,Agreement__r.Customer__r.name from Agreement_Line__c where id=:AgreementLineId];
Customer=al.Agreement__r.Customer__c;
customerName=al.Agreement__r.Customer__r.name;
Products = [SELECT id,name ,Agreement_Line__c,Products_ID__c FROM Products__c WHERE Agreement_Line__c=:al.id ];
for(Products__c pro : Products)
{
proIds.add(pro.Products_Id__c);
}
customProducts = [SELECT Id, Name FROM Product__c WHERE Id IN :proIds];
}
public List<ProductsUnderService> getProductsUnderService()
{
ProductsUnderServiceList=new List<ProductsUnderService> ();
List<Installed_Products__c> iproducts = [select Name,
Description__c,
Serial_ID__c,
Asset_Tag__c,
Quantity__c,
Agreement_Line__c,
Products__c,
Site__c,
Customer__c from Installed_Products__c where Customer__c=:customer AND Products__c IN:proIds limit 4];
For(Installed_Products__c ip :iproducts )
{
iprodIds.add(ip.Id);
}
List<Products_Under_Service__c> Productserrvice =[select id,name,Installed_Productss__c from Products_Under_Service__c
where Agreement_Line__c=:AgreementLineId AND Installed_Productss__c IN:iprodIds ];
For(Installed_Products__c ip :iproducts )
{
integer i=0;
For(integer temp=0;temp<Productserrvice .size();temp++ )
{
if(Productserrvice[temp].Installed_Productss__c == ip.id)
i++;
}
if(i==0)
ProductsUnderServiceList.add(new ProductsUnderService(ip));
}
if(ProductsUnderServiceList.isEmpty())
ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.ERROR,+ 'There are no Installed Products for '+customerName+' Account'));
return ProductsUnderServiceList;
}
public PageReference Add()
{
List<Products_Under_Service__c> listPus;
for(ProductsUnderService ip:ProductsUnderServiceList)
{
if(ip.selected==true)
{
Products_Under_Service__c pus= new Products_Under_Service__c(Installed_Productss__c=ip.id,
Agreement_Line__c =AgreementLineId);
//insert Pus;
//listPus.add(pus);
}
insert listPus;
}
PageReference p=new PageReference('https://ap1.salesforce.com/'+AgreementLineId);
return p;
}
public PageReference cancel()
{
PageReference p=new PageReference('https://ap1.salesforce.com/'+AgreementLineId);
return p;
}
public class ProductsUnderService
{
public Installed_Products__c con {get; set;}
public String id{get;set;}
public Boolean selected {get; set;}
public String aggreementLine{get;set;}
public ProductsUnderService(Installed_Products__c ip)
{
id=ip.id;
con = ip;
selected = false;
}
}
}
Any help is Appriciated
Looks like you are trying to add items to the ListPus variable but you never initialized it.
You need to change
To
And then uncomment the line that adds items to your list.
Additionally, you probably need to move your declaration:
Products_Under_Service__c pus
Outside the for loop, as well as the insert statement, so it's only called once
Final result:
Gabriel Alack
Contact Us - We Can Help!
Salesforce Superheroes
------------------------------
help@salesforcesuperheroes.com
www.salesforcesuperheroes.com
1-888-407-9578 x122
Yes it is not giving error but the
Products_Under_Service__c pus is not creating even i am checking true also
Here records are not inserting
Would you please look into that toatal code and let me know where i made a mistake??
You're going to need to examine what's going on further up in your execution chain. I wouldn't be able to tell just by looking at it.
Have you checked to see if your products service list is even being populated? Try putting some debug statements around it and see if your lists are empty for some reason.
Or if you need someone to log in and take a look at it for you, that's what we do :)
Gabriel Alack
Contact Us - We Can Help!
Salesforce Superheroes
------------------------------
help@salesforcesuperheroes.com
www.salesforcesuperheroes.com
1-888-407-9578 x122