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
RiothamusRiothamus 

Getting APEX class name

I'm looking for an APEX method that tells me if an APEX object 'is a kind of' object or failing that, to get the Class Name.

 

Psuedo-code:

 

class A {

};

class B extends A {

};

class C extends A {

};

 

function some_function(A aobj) {

  if (a.isKindOf(B)) {

     // do something with B

  } else if (a.isKindOf(C)) {

     // do something with C

 }

 

Thanks!

 

 

 

 

kiranmutturukiranmutturu

you can make use of instanceof keyword check here

MoUsmanMoUsman

Hi Riothamus,

 

You can use instanceof Keyword it will return true if it is instanceof of the given object Example is given below.

 

If (aobj instanceof A) {
    // Can safely cast it back to a A object 
   A a = (A) aobj;
   } Else {
   // Do something     
}
//Do same for all your classes

 --

Thanks

Usman