1

I would like to get Apex class name without namespace prefix. I wonder if exists any equivalent method like known in Java getSimpleName() ?

Existing method getName() returns apex class name with namespace like follows:

enter image description here

2

No such reflection is available in Apex. If you want to know they type name, you will have to implement it manually.

public class MyType
{
    public String getTypeName() { return 'MyType'; }
}
7
  • But there are other ways of getting the class name: salesforce.stackexchange.com/questions/23998/… Jul 5 '18 at 20:16
  • @renato-oliveira IMHO additional split or substring only for get class name isn't elegant approach.
    – gpoluch
    Jul 5 '18 at 20:21
  • Btw. I wonder why getSimpleName() isn't available in Apex which in fact is based on Java lang? How about posting that Idea on Trailblazer Community?
    – gpoluch
    Jul 5 '18 at 20:27
  • 1
    Because Apex does not support reflection. Not sure why they made that design decision, and I think it would be hard for anyone not working directly on the language to answer that sort of question.
    – Adrian Larson
    Jul 5 '18 at 20:28
  • Thanks @adrian-larson . Also I am confused why exists method MyApexClass.class.getName() which in fact returns apex class name, but with namespace prefix.
    – gpoluch
    Jul 5 '18 at 20:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.