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

how to know Data Type?
Hello All,
I have created List<Object> objList = new List<Object>();
Now I have requirement to know the what is the datatype of the value stored in this list.
How we get to know the datatype of the stored value ? Is there any method ?
i.e. objList = {'hello',1234.56,12};
how we get to know that 2nd value in the list is Number Or decimal Type?
Please Help me to solve this issue?
You can use the instanceof keyword to determine if the object is a particular type. Unfortunately this means that you end up with a potentially large if statement. E.g.
All Answers
You can use the instanceof keyword to determine if the object is a particular type. Unfortunately this means that you end up with a potentially large if statement. E.g.
Hello bob,
Thank you for quick response.
I have tried your code and i am able to save the code by applying your changes but it does not appear into my vf page. code is given below:-
Piece Of code of My visual force page is given below :
and i have Bill to# column which is String so I want to put '-' in this column but i am not able to get this changes.
Is your type definitely a double or a string?
Hello Bob,
My Bill to column type is String and other column contains Double Value. here is the output of the code.
I've just tried the following in my dev org:
and the output is:
so it looks to be working. Have you added debug to confirm that you definitely have the correct type (e.g. add an else clause with some debug).
Hello bob,
can Object Data Type contain String data Type ? I am facing error i.e. '-' is not a valid Number. why it is showing me ?
That implies that you are trying to store a string into a numeric (Double/Decimal/Integer/Long).
I've just tried the following in my dev org and it works correctly:
Giving the output:
Hello bob,
One thing i forgot to tell you. My obj value is null so how can i check that ?
Ah, that changes things, as null will return true for instanceof in all cases. Looking back at your earlier code, if you are using sobject fields, you can use the describe capability to determine the type of the field.
If you aren't using sobject fields, I seem to recall doing something along these lines a while ago where I used exception handling to attempt to set a string value, if that failed try a double value etc. I can't remember if that was a total success or not though.
Hello bob,
Thank you for helping me. Now i know i can not do it using instanceOf so i have to do it using schema.describe.
Hello bob,
I am facing another problem.As i said i have List<Object> which contains (162, 0.0, 0.00, 0.0, - ) values but when i am trying to display it in visualforce page inside repeat it shows me following error. what is the reason behind it?
What markup are you using to display these values?
Hello bob,
I am using <apex:outputText> to display the value. I have developped another page which has the same functionality.In that page List<Object> is displayed usind HTML markup. I have tried HTML markup also but still the error is occuring.
I don't see why ouputtext would be trying to turn the string into a number - are you using formatting/nested apex:param tags?
Hello bob,
I have requirement to use that but just now i am not using anything.I simply putdown <apex:outputText> {!obj} </apex:outputtext>
Can you post the full code - controller and page?