function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
margotqmargotq 

Error when creating a new record with a blank 'long text area' field.

When using the API to create a new lead record, if we try to insert a blank value into a custom field of type "long text area", an error is returned.

If we change the blank string to a value (e.g. "x"), the new record is created without a problem.

Any ideas why?

SuperfellSuperfell
perhaps if you said what the actual error is, it might be easier to diagnose
margotqmargotq

OK

I have a function called Lead_Create that takes in a handful of string variables and generates a Lead record. One of the variables is named "iComments", which contains the text that I want to insert into the "Comments__c" field. Below is a snippet of the function:

Lead lead = new Lead();
lead.Email = iEmail.Trim();
lead.Comments__c = iComments.Trim();

sObject[] newLead = new sObject[]{ lead };
SaveResult[] sr = sfbinding.create( newLead );

if ( sr[0].success != true )
   return "ERROR: " + sr[0].errors[0].message;
else
   return sr[0].id;

When the string "iComments" is a blank string, the web code that calls this particular function Lead_Create generates the following error:

Error Type:
sfAPI (0x80004003)
Object reference not set to an instance of an object.

Which indicates that the function completely failed. When the string "iComments" is not blank, there is no error, and everything works as planned. I should note that this function was working prior to adding the "iComments" variable.

SuperfellSuperfell
probably becuse you're calling Trim() on a null, try

lead.Comments__c = iComments == null ? null : iComments.Trim();
margotqmargotq

Nope, no luck.  The string isn't a null, because I am testing by actually setting the variable to a blank string and it still fails.  I have other variables that are blank strings (phone number and other custom fields) and those have been working fine with the Trim() method.

Hmmm.

SuperfellSuperfell
Which line generates the error ? have you stepped through it to see where the NPE is coming from ?