You need to sign in to do that
Don't have an account?
Victor P
Function in an apex trigger that looks for null value and returns an empty space
I'm trying to create a quick function that I can reuse throughout the code that replaces a null value with an empty space.
Here's how I do it at the moment:
CheckForNull(opportunity.details__c) would be easier.
Here's my poor attempt:
Here's how I do it at the moment:
String.isBlank(opportunity.details__c)? '' : opportunity.details__c)I need to reuse this a lot throughout the code so something simple like
CheckForNull(opportunity.details__c) would be easier.
Here's my poor attempt:
function CheckForNull (search) { var checked = String.isBlank(search)? '' : search) return checked; }
1. You can use String.isEmpty(empty) , String.isBlank(blank) methods for this:
https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_methods_system_string.htm
So you have to use like below:
public static String isEmptyString(String inputString)
{
String str = String.isBlank(inputString)?'': inputString;
return str;
}
=================================
So in Class you have to use like below:
Public class Sample
{
Public static void sampleMethod()
{
String testString = isEmptyString( 'Not a Empty String');
}
Public static Boolean sampleMethod1()
{
String testString = isEmptyString( '');
return testString ;
}
public static String isEmptyString(String inputString)
{
String str = String.isBlank(inputString)?'': inputString;
return str;
}
}
Thanks,
Maharajan.C
All Answers
1. You can use String.isEmpty(empty) , String.isBlank(blank) methods for this:
https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_methods_system_string.htm
So you have to use like below:
public static String isEmptyString(String inputString)
{
String str = String.isBlank(inputString)?'': inputString;
return str;
}
=================================
So in Class you have to use like below:
Public class Sample
{
Public static void sampleMethod()
{
String testString = isEmptyString( 'Not a Empty String');
}
Public static Boolean sampleMethod1()
{
String testString = isEmptyString( '');
return testString ;
}
public static String isEmptyString(String inputString)
{
String str = String.isBlank(inputString)?'': inputString;
return str;
}
}
Thanks,
Maharajan.C
{
String str = String.isBlank(inputString)?'': inputString;
return str;
}
THIS.
I was pretty close :). Thank you Maharajan.C!