Questions tagged [null-pointer]

The tag has no usage guidance, but it has a tag wiki.

Filter by
Sorted by
Tagged with
7
votes
1answer
3k views

Force Dynamic Soql results to include fields with null value

So I've read a lot about this and it seems that queries run with Database.query(queryString) will skip over any field values set to null instead of returning the property set to null This has cause a ...
5
votes
1answer
430 views

Attempt To dereference null object for != in if and no error for == in if

I have been trying to use this code: system.debug('aaaa'+o.Registration_No__c); if(o.Registration_No__c !=null || o.Registration_No__c.trim() !='') { bFirst.RegisterNo = o.Registration_No__c ; }...
4
votes
1answer
2k views

Why does this call to Trigger keySet() throw a null pointer exception?

I have a simple trigger like: trigger littleTrigger on Custom__c (before insert) { Set<Id> idSet = Trigger.newMap.keySet(); //Some stuff } Why could the second line throw a null ...
4
votes
1answer
3k views

Apex `if (Boolean) `. Null exception virtually renders this check useless and unsafe

Being that an if (booleanVariable) check, where booleanVariable is null, throws a NullPointerException, it would seem that this check is unsafe. If so why would Apex allow it? This is especially true ...
4
votes
1answer
3k views

Access user creating a record in before insert trigger

I'm trying to set some default values for contact fields based on which user is inserting the record into the database, but am coming up against a NullPointerException as the CreatedById is null ...
4
votes
2answers
891 views

Null Pointer Exception add AccountId to WhatId for Task

Trying to build what I thought would be a simple trigger: when a task is created that is only related to a contact (WhoId = contact type, but WhatId = null), relate the task's WhatId to the contact's ...
4
votes
2answers
87 views

Failing test is showing as passed

In Debug Logs I can see a System.NullPointerException for the unit test that was just run, but on the Apex Test Execution page I see the test as passing. The error is not buried within the log details;...
3
votes
3answers
1k views

Null Pointer Exception When Incrementing Variable

I'm getting a Null Pointer Exception in a utility method I wrote to update some contacts. What can I do to prevent a null pointer exception when I modify this field? public void AddEL() { //...
3
votes
4answers
2k views

|FATAL_ERROR|System.NullPointerException: Attempt to de-reference a null object on my Apex Trigger

I'm kind of new in Apex development and I'm writing a before insert, before update trigger to a custom object that is going to be upserted through an API integration. Is very basic code but I don't ...
3
votes
2answers
961 views

In this code, where is the attempt to de-reference a null object?

I've got some simple code and I'm wondering if someone can help me understand why it would result in the "Attempt to de-reference a null object" error? This is part of a custom controller that I'm ...
3
votes
4answers
2k views

Test method fails with “Attempt to de-reference a null object” Trying to use 2 record types of contact

In a test class, I need to have 2 contacts with different record types. Contact Record Types: Client_Only and Candidate. Account Contact is Client only, and Applicant is Candidate. Line 8 is ...
3
votes
1answer
3k views

System.NullPointerException: Script-thrown exception

I'm trying to create a trigger which updates the Account owner based on the detail object criteria. The account assignment should be in a round robin fashion so that accounts will be distributed ...
3
votes
1answer
8k views

Attempt to de-reference a null object: Trigger

There were custom validation error(s) encountered while saving the affected record(s). The first validation error encountered was: Apex trigger updatequotestatus caused an unexpected exception, ...
3
votes
1answer
813 views

attempt to de-reference null object in test class

I'm attempting to write a test method for my constructor and when I get to a method in my non-test class where I'm assigning a value to the object passed I get a "attempt to de-reference null object ...
3
votes
1answer
2k views

Issue with Invocable Method to Call Queueable

Ok, I'm officially confused. I've written some code to attempt to populate a Campaign lookup field on Opportunity based on some logic. The basic flow is Process Builder (so the client can ...
3
votes
1answer
1k views

NULL lookup field in Test Class

I'm getting a null value on a lookup field when running a test class. Account a = new Account(Name = '1', Owner = u, CurrencyIsoCode = 'CAD'); insert a; a = [SELECT id, AccountNumber, Name, ...
3
votes
1answer
326 views

Null Pointer on system.debug in @future method

Can someone explain the error? I have a trigger that passes a set of Event IDs to an @future clas. Below is the class: public class eventChatterFuture{ @future public static void ...
3
votes
1answer
89 views

NullPointerException BeforeInsert on Lead Trigger

I am pretty new to writing custom code in SF and would appreciate any help. I have a trigger on Leads to update Status to "Contacted" when a task on that Lead is "Completed". I found this in a ...
3
votes
2answers
1k views

Comparision directly on null value safe?

So many times, we do a null check of a field value and then compare them boolean checkAmountGreaterThan10k(Opportunity record){ if(record.Amount!=null){ return record.Amount > 10000; ...
3
votes
1answer
317 views

NULL POINT Exception

I am getting NULL POINT Exception error when running my unit tests and can't seem to figure out how to go about this one. This is the error Message; |FATAL_ERROR|System.DmlException: Insert failed....
3
votes
2answers
2k views

Why is this Apex Trigger throwing a Null Pointer Exception: Argument cannot be null?

This trigger references blank fields, and complex formula fields. The reason I'm trying to do a trigger and not a formula is that it resolves to too many characters because of referenced formula ...
2
votes
1answer
378 views

Is there any way to make an Apex method parameter lazy?

Let's say I want to call a method like: doSomething(a.b.c.d.e.f()); I know that this might be an expensive operation and a, a.b, a.b.c, a.b.c.d, and a.b.c.d.e might all be null, however I would ...
2
votes
1answer
2k views

System.NullPointerException when using .contains in a for loop

I am iterating through an array of a List of Maps and want to run an if function whenever an item from the list meets a condition. The problem I am currently facing is Salesforce producing the ...
2
votes
1answer
532 views

Apex Rest Wrapper - Error Attempt to de-reference a null object

So I've done quite a bit of searching on the forum and am learning a ton. I really appreciate the experts on this forum who are willing to help out. I am taking inspiration/following the code posted ...
2
votes
1answer
152 views

NullPointerException in a trigger framework

I'm trying to adapt to Tony Scott's tidy trigger pattern. I'm trying to prevent users from uploading more than certain size of attachments. I have written the Handler class for Attachment object and ...
2
votes
1answer
93 views

Attempt to de-reference a null object when using alternative to getGlobalDescribe

In the following code String myString = 'Account'; SObjectType sObjType = ((SObject) Type.forName(myString).newInstance()).getSObjectType(); When myString = a object name does not exist i get a ...
2
votes
2answers
119 views

Unable to handle Attempt to de-reference a null object with map

I'm working on after update trigger. And it's throwing an exception after I'm checking null values too. i don't have any idea why it's public void AfterUpdate(Map<Id, SObject> newItems, Map&...
2
votes
1answer
792 views

Calling JSON.deserialize() throws "System.NullPointerException: Attempt to de-reference a null object"

I'm trying to use the System method JSON.deserialize(jsonString, apexType) to deserialize the body of an ApexRest POST request. My code compiles, but at runtime I'm getting a System....
2
votes
1answer
2k views

Attempt to de-reference a null object

When I try to load the visualforce page it gives me the error "Attempt to de-reference a null object " I have narrowed it down to the line of code lstNotes.add(new NoteWrapper(lstNotes.size(),new ...
2
votes
2answers
2k views

De-reference null object error on Trigger - error only when value is null

I have a trigger and an Account handler. I have an error on record insert. Trigger calls Accounthandler.OnAfterInsert(Trigger.new, Trigger.newMap); Here is a simplified version of the handler top ...
2
votes
1answer
32 views

Help with my Trigger Logic

In the Below code I want to assign Case to WhatId in my Task record when a case with the same contact as Opportunity is created. I am getting a System.NullPointerException at tsk.WhatId = cas1.Id when ...
2
votes
1answer
278 views

CampaignMember.getSobjectType() returning null

Whenever i am calling CampaignMember.getSobjectType() method , getting nullpointer exception. I tried to debug the CampaignMember object but getting null value object as well. Marketing User checkbox ...
2
votes
1answer
131 views

Null Pointer if sObjectType isn't Case

I have the apex trigger below that is meant to check the WhatId on a new Task if the WhatId belongs to a case. The trigger then populates fields on the related Case for ActivityDate and Task Type. ...
2
votes
1answer
126 views

Using rendered="" parameter causes checkbox to evaluate to null

Putting checkbox inside outputpanel or using rendered on itself, will display correctly, but will cause null de-reference when its used in the class. What is the reason behind? This works: <apex:...
2
votes
1answer
598 views

How can I dynamically transverse dynamically SOQL'd SObject fields in Apex?

So, in my other post, I figured out for myself how to dynamically transverse SObject fields in Apex. But within the context of my work, there is a problem with the solution as it currently stands: ...
1
vote
2answers
714 views

Trigger Error in salesforce

When I used to create the record in Event object it is showing error like: Error: Invalid Data. Apex trigger General_Event_Trigger caused an unexpected exception, contact your administrator: ...
1
vote
1answer
983 views

Test Method throwing null pointer exception on custom setting

I am trying to write a test class. My Apex class has the following constructor: public NController(ApexPages.StandardController controller) { cas = (Case) controller.getRecord(); csId = ...
1
vote
2answers
645 views

Attempt to de-reference a null object in trigger to create child object upon field change

I have created a trigger on the Project custom object, to create a record in the Project Note custom object when the description field is modified. Running the unit test however, I receive the ...
1
vote
2answers
751 views

Substring is getting nullpointer exception

I have a map of contacts. Need to print substring of title. but it errors out, when title is null : System.NullPointerException: Attempt to de-reference a null object public class k { public ...
1
vote
1answer
140 views

Attempt to De-Reference a null object won't except data

I have an issue when I try to input data into a custom object. On line 14 is where I'm getting the NullPointer. System.debug(testAccount[0].name) outputs an account name created in line 8. But when ...
1
vote
2answers
93 views

Apex class in trigger populates lookup based on string input

I am writing a trigger on my Case object to run (before insert). I am receiving the following error: System.DmlException: Insert failed. First exception on row 0; first error: ...
1
vote
2answers
600 views

Attempt to Dereference to null object on trigger

I am trying to update child object(Task) from Parent object(Enrolmentform__c). When I am trying to stamp the value, I am getting null pointer exception . if(trigger.isafter && Trigger....
1
vote
2answers
320 views

test class error - attempt to de-reference a null object Trigger using oldmap

I am receiving an Error in my Test class, but am unsure of the reason why. Here is the Error: Exception: Update failed. First exception on row 0 with id a0i4C000000HfieQAC; first error: ...
1
vote
1answer
628 views

Trigger Null pointer exception

I have this trigger that errors out at line 13 NullPointerException attempt to de-reference a null object in Apex Trigger Code trigger Event_Attendee_vod on Event_Attendee_vod__c (before update, ...
1
vote
1answer
899 views

NullPointerException; why am I getting this?

I am at a loss as to why this trigger is throwing up a NullPointerException... it isn't clear to me, as I am querying for the OwnerId before I loop through my inserted tasks. The error message is as ...
1
vote
1answer
275 views

NullPointerException: Attempt to de-reference a null object in a batchclass

I have this batchclass with which I want to update some checkboxes on account with the values of related assets checkbox values. When running the class I get an System.NullPointerException: Attempt to ...
1
vote
1answer
480 views

Try/Catch for Attempt to Dereference Null Object

Is there a way I can test with an IF statement for a null object. Using an IF (obj==null) throws the error. How can I account for these? With SOQL, I use a list and check the number. However, the ...
1
vote
2answers
3k views

Attempt to de-reference a null object on Map

I'm building a method to update two date fields when a different date field is edited. When I update one of the date fields or both of the fields the error in the debug log is "Attempt to de-reference ...
1
vote
2answers
2k views

Argument 1 Cannot be Null in For Loop

I have the below method that populates a selectlist on a VF page: User u = [SELECT Id, ContactId, FirstName FROM User WHERE Id = :UserInfo.getUserId()]; Contact c = [SELECT Id, LastName, ...
1
vote
2answers
52 views

Attempt to de-reference a null object error while accessing field in the Account object

I have a Quote__c object which has a field named FieldTpReferAccount__c which refers to Account. The Account object has a custom field named FieldInAccount__c. I need to update FieldInAccount__c in ...