I have this trigger that changes the Name of a record based on a custom title__c
field:
trigger assignDegreeName on Degree__c (before insert) {
/**
Variables
**/
integer maxSize = 80;
/**
Assign Name to new Degree
**/
for (Degree__c newDegree: Trigger.New) {
string degreeName = newDegree.title__c;
if (degreeName.length() > maxSize) {
degreeName = degreeName.substring(0, maxSize);
}
newDegree.Name = degreeName;
}
}
title__c
is a required field, and I know that the endpoints we use to create Degrees will send an empty string, not null, for title anyways. So it should never be null and even if it is, it shouldn't get to this point in the trigger without failing in the first place because of the requirements.
Yet, I always get the error response attempt to de-reference a Null object
on row 400
when I hit the api endpoint that uploads a bunch of degrees at once.
What could possibly be Null in this trigger?
degreeName
. What do you see when you log a system.debug onnewDegree.title__c
, does it contain anull
value at all?''
not null...''
andnull
are different.''
is an empty string with size = 0. Strings don't get casted to''
if the value isnull
."\u0646\u0638\u0645 \u0627\u0644\u0645\u0639\u0644\u0648\u0645\u0627\u062a \u0627\u0644\u062d\u0627\u0633\u0648\u0628\u064a\u0629"
and that is what is being considerednull