You need to sign in to do that
Don't have an account?
Amit Yadav 9
Attempt to de-reference a null object
public void fun()
{
list<Payment__c> pay=new list<Payment__c>();
for(Payment__c nop:[select id,,npe01__Scheduled_Date__c, from Payment__c where Paid__c=true])
{
integer year=nop.npe01__Scheduled_Date__c.year();
integer month=nop.npe01__Scheduled_Date__c.month();
}
when i run this code in developer console in production it gives error:
System.NullPointerException: Attempt to de-reference a null object
on the highlighted part.
This is working fine in sandbox. Deployed without any problems.
Checked the query in query editor. It is returning records as expected.
What could be the problem here???
Any help is appreciated.
Thank you
{
list<Payment__c> pay=new list<Payment__c>();
for(Payment__c nop:[select id,,npe01__Scheduled_Date__c, from Payment__c where Paid__c=true])
{
integer year=nop.npe01__Scheduled_Date__c.year();
integer month=nop.npe01__Scheduled_Date__c.month();
}
when i run this code in developer console in production it gives error:
System.NullPointerException: Attempt to de-reference a null object
on the highlighted part.
This is working fine in sandbox. Deployed without any problems.
Checked the query in query editor. It is returning records as expected.
What could be the problem here???
Any help is appreciated.
Thank you
You have to add null condition in your query or before processing the logic,
Way 1:
Way 2: