+ Start a Discussion

Getting current class/method name



I'm developing error logger for SFDC and im courius is there a way to get current class and method name?

E.g. i want to add in catch exception brackets line:


logNewError(currentClassName, currentMethodName, errorDescription).


I hope you got my point;)


Best Regards,



The Exception class includes the method and class that caused the error.



Error: Invalid Data. Review all error messages below to correct your data. Apex trigger AccountTrigger caused an unexpected exception, contact your administrator: AccountTrigger: execution of AfterUpdate caused by: System.DmlException: Update failed. First exception on row 0 with id a0a30000000t0OmAAI; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, ServiceEntitlementRYG: execution of AfterUpdate caused by: System.ListException: Duplicate id in list: 0013000000M2efHAAR Class.trafficLightUtils.updateServiceEntitlement: line 27, column 13 Trigger.ServiceEntitlementRYG: line 17, column 7: Class.SyncAccountMemberOwner.updateServiceEntitlements: line 59, column 3







I need to retrieve the current class name and current method name within catch block to log the exception..Could  u plz tell me which method of exception class should i use to get this..



Thanks in advance,








Did you figure out how to do this?  I am looking at doing the samething.


Matthew KeefeMatthew Keefe
It's been a while on this thread, but I only just found it today. Here's something I found that works:

String CurrentClassName = String.valueOf(this).substring(0,String.valueOf(this).indexOf(':'));

This works where the value of "this" is the class (or the code is contained by a class).
Pradeepkumar Dani 5Pradeepkumar Dani 5
Matthew, That was helpful. Thanks
Pradeepkumar Dani 5Pradeepkumar Dani 5
You can play around "this" operator.