You need to sign in to do that
Don't have an account?
ShadowlessKick
Null Errors
Could someone explain how you convert null value errors returning from fields collected in an SOQL Query?
Error: System.NullPointerException: Argument 1 cannot be null
Opportunity theOpportunity = new Opportunity(); for (Opportunity theOpportunity:[select Id, Quote__c from Opportunity Limit 1]) { String TestField; TestField = String.valueOf(theOpportunity.get('Quote__c')); System.debug('The Value 1 :' + TestField); TestField = String.valueOf(theOpportunity.Quote__c); System.debug('The Value 2 :' + TestField); }
Would have thought that the String.valueOf would convert null to ''.
Thank you for your help. I was hoping there was a magic APEX function that would convert a NULL value to an empty string. It looks like that has to be coded manually.
All the fields that could possibly end up with a value of NULL were collected in a list. Through a loop, each field was checked replacing NULL with an empty string. This method does not handle NULL dates.
None of the fields could be NULL because they were being used in an XML "writeCharacters" function. The NULL values were throwing an error.
Xmlstreamwriter w = new Xmlstreamwriter();
w.writeCharacters(String.valueOf(theOpportunity.get('Quote__c')));
All Answers
Salesforce has a lot of quirks like this that are very annoying.
Try this though:
Thank you for your help. I was hoping there was a magic APEX function that would convert a NULL value to an empty string. It looks like that has to be coded manually.
All the fields that could possibly end up with a value of NULL were collected in a list. Through a loop, each field was checked replacing NULL with an empty string. This method does not handle NULL dates.
None of the fields could be NULL because they were being used in an XML "writeCharacters" function. The NULL values were throwing an error.
Xmlstreamwriter w = new Xmlstreamwriter();
w.writeCharacters(String.valueOf(theOpportunity.get('Quote__c')));