You need to sign in to do that
Don't have an account?
S@uravv
System.NullPointerException: Attempt to de-reference a null object, How to solve
When I try to Query
Invoice__C[] InvoiceData = [Select Id,Attachment_Id__c,Supporting_Attachment_Id__c from Invoice__c where Id=:InvoiceId];
In the debug I see Only Id and Attachment_Id__c fields, because Supporting_Attachment_Id__c is null.
But then I try to check it using below line.
if(InvoiceData[0].Supporting_Attachment_Id__c == ''||InvoiceData[0].Supporting_Attachment_Id__c == null)
It throws System.NullPointerException: Attempt to de-reference a null object.
How to solve this issue?
Invoice__C[] InvoiceData = [Select Id,Attachment_Id__c,Supporting_Attachment_Id__c from Invoice__c where Id=:InvoiceId];
In the debug I see Only Id and Attachment_Id__c fields, because Supporting_Attachment_Id__c is null.
But then I try to check it using below line.
if(InvoiceData[0].Supporting_Attachment_Id__c == ''||InvoiceData[0].Supporting_Attachment_Id__c == null)
It throws System.NullPointerException: Attempt to de-reference a null object.
How to solve this issue?
Please debug the 'InvoiceData[0]' as well. See if it is printing NULL ?
Probably your query is not returning a record.
Thanks,
Ashvin
hi Saurav,
try
if(!String.isBlank(InvoiceData[0].Supporting_Attachment_Id__c)) {
//your condition if there is a value
}
System.debug doesn't print fileds with null value. Hence I am getting only Id and Attachment_Id__c in my debug.
try following way. let me know if it helps you and marking it as best.
Thank you
It gave me the same error with your solution.
But I ran into a similar issue in which the insert operation is not letting me access the id of the inserted record.
It throws a null pointer exception. Though the record is getting inserted, I checked on Workbench.
insert supportAttachment;
system.debug('Attachment Inserted');
supportingAttachmentId = supportAttachment.id;
Did you check if it is returning any exception or validation error which is preventing the insert supportAttachment operation ? Are you using try catch block ?
Also add the debug for supportAttachment after insert dml. Check if it is displaying the ID field, in this case it will not but just have a look.
Thanks.
Ashvin