1

I'm getting the values of a contact and generating an XML with respective Contact Details through Concatenation. Here, the problem is when contact fields doesn't have a value its displaying NULL. I want to replace it with EMPTY string. Is there any way ?

2
  • Where you are showing them, on Vforce page?
    – Ashwani
    Jun 23, 2015 at 7:39
  • @Ashwani I want to store the XML in Salesforce.
    – Rv1
    Jun 23, 2015 at 7:42

1 Answer 1

2

If you are using Apex, the you can simply check and replace them with null when you will show them like.

ex. if resultant variable is contact.field_name then you can simple change them:

contact.field_name = (contact.field_name != NULL ||  contact.field_name != 'NULL') ? contact.field_name : '';

if showing on visualforce page:

{!IF( OR(contact.field_name != null, contact.field_name != 'null'),contact.field_name, ''}

and if you get the xml as string then simply replace the complete string as:

String refinedString = xmlString.replace('NULL',''); 

but make sure your xml names don't contain 'null' combination anywhere except the value null

2
  • ThanQ @Ashwani.
    – Rv1
    Jun 23, 2015 at 8:04
  • But what if the value inside the string is actually a null (\x00)?
    – tggagne
    Jan 10, 2017 at 18:07

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .