+ Start a Discussion
karthik karthikkarthik karthik 

How to Replace null value fields with empty string and return all fetched fields

Hi All,

​Using SOQl I have fetched 4 fields all the fields are Text datatypes, if any fields have null value i want to replace null value with empty string and return all 4 fields. Please i need urgent help can anyone send some sample code. 

Thanks in advance.
Best Answer chosen by karthik karthik
Arun KumarArun Kumar
So if are using Salesforce API there are methods availble to check the DataType for the fields. And simple solution to be go for below logic
if(CHECK Euals to NULL){ ASSIGN blank value} else if(CHECK Equals to BLANK OR '0'){ Assign blank value}

Thanks,
Arun

All Answers

Arun KumarArun Kumar
Hi Karthik,

Please see the below code
//Assuming String fields str1, str2 and so on
String  tempStr1= (String.isBlank(str1)? '' : str1);

String  tempStr2= (String.isBlank(str2)? '' : str2);

String tempStr3= (String.isBlank(str3)? '' : str3);

String tempStr4= (String.isBlank(str4)? '' : str4);

Use tempStr1, tempStr2 fields for your code.

Please let me know if the helps.

As a common practice, if your question is answered, please choose 1 best answer.
Additionaly you can give every answer a thumb up if that answer is helpful to you.

Thanks,
Arun
karthik karthikkarthik karthik
Hi Arun,

Thanks for your response, Currently i'm working on integration here i have a single record at a time. In that record have multiple fields and multiple datatypes. How to put empty data string or null based on datatypes, ex: i have 10 fields in my query all are different datatypes how could i find if i get string or integer or some other datatype. Please i need help.

Thank you.
 
Arun KumarArun Kumar
Hi Karthik,

the data you are getting is from SALESFORCE or 3rd party?
karthik karthikkarthik karthik
Data getting from salesforce.
Arun KumarArun Kumar
So if are using Salesforce API there are methods availble to check the DataType for the fields. And simple solution to be go for below logic
if(CHECK Euals to NULL){ ASSIGN blank value} else if(CHECK Equals to BLANK OR '0'){ Assign blank value}

Thanks,
Arun
This was selected as the best answer