function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Suraj GharatSuraj Gharat 

How to get name of the class from its instance

Hi All,
I've situation where I need to get the name of the Apex class from its instance.
The declared instance variable is of very generic type (Object) and using this variable, I need the name of the specific class from which the object was instantiated.

Because of my requirements I cant use instanceof here, and I dont want to resort to "String.valueOf(obj)" as this is not the reliable way.

Please assist.
what's preventing you from using instanceof? can you post code?
Suraj GharatSuraj Gharat
Actually there could be a large number of specific classes from which the instantiation takes place; Moreover these kind of classes would increase as the developement proceeds, and hence it would be little annoying to change your code everytime to add the new class into your "instanceof" checks.

For the sake of confidentiality I cant post the code here, but yes this is the concept.