You need to sign in to do that
Don't have an account?

Convert To Boolean - System.TypeException: Invalid boolean: true
Hi All,
Amazing how the simplest things are the most challenging.
I'm trying to convert a string of false / true to a boolean, I've tried the code below and I keep getting 'System.TypeException: Invalid boolean: true'. I have no idea why, as my other type conversions are working fine.
Code below is an extract of a test function, the actual usage is in a much larger method! Please help!
public class convertToBool
{
public static void testConvert()
{
Integer i;
String s;
s='10';
i=integer.valueof(s);
system.assertEquals(10,i); //this test passes
string asdf = 'true';
//boolean bob = boolean.valueof(asdf);
system.debug(Boolean.valueOf(asdf));
}
public static testMethod void testConvertToBool()
{
testConvert();
}
}
Amazing how the simplest things are the most challenging.
I'm trying to convert a string of false / true to a boolean, I've tried the code below and I keep getting 'System.TypeException: Invalid boolean: true'. I have no idea why, as my other type conversions are working fine.
Code below is an extract of a test function, the actual usage is in a much larger method! Please help!
public class convertToBool
{
public static void testConvert()
{
Integer i;
String s;
s='10';
i=integer.valueof(s);
system.assertEquals(10,i); //this test passes
string asdf = 'true';
//boolean bob = boolean.valueof(asdf);
system.debug(Boolean.valueOf(asdf));
}
public static testMethod void testConvertToBool()
{
testConvert();
}
}
Why not go straight and use the ineteger value and a boolean, instead of what you doing.
for example:
String s;
s='10';
i=integer.valueof(s);
system.assertEquals(10,i);
Can be simply:
int s = 10;
and:
string asdf = 'true';
boolean asdf = true;
Unless you have a reason for doing this, tell the forum why this.
Message Edited by Losintikfos on 09-22-2008 04:50 AM
You can try the conversion in apex! see what happens and let the forum know about the end result.
Thanks for the post, we need to convert the date we receive from an external source that is all typed as text into a boolean for a field in sf.com as we can't get the provider to change the data types for us.
I tried your java method but it doesn't exist in APEX, and the strange thing is that it won't convert an integer to a boolean, when the docs say 0 = false and 1 = true.
Any assistance would be great.
It is possible to to change the field type in salesforce to text? or this will fire a crash to some dependable applications.
Cheers,
B
like this
This will make sure everytime it encounters the string value true the handler is set to true, else otherwise. Note you can pass multiple test condition using pipe. Example;
I have same issue, did you find the answer?
it's very strange situation...
It may be a bug... I think...
but I followed the Losintikfos's suggestion, it works.
thanks, Losintikfos!
this case doesn't work...
String value = ApexPages.currentPage().getParameters().get('value');if (value != null){checkboxvalue8 = Boolean.valueOf(value);}
but this solution works!!
String value = ApexPages.currentPage().getParameters().get('value');if (value != null && value == 'true'){checkboxvalue8 = true;}