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
lukskrodzlukskrodz 

Getting current class/method name

Hello,

 

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,

Lukas

mikefmikef

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

 

 

 

SuvraSuvra

Hi,

 

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,

Suvra

 

 

 

dke01dke01

 Hi,

 

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
Adrien MARSOULAUDAdrien MARSOULAUD
https://salesforce.stackexchange.com/a/153836
Pradeepkumar Dani 5Pradeepkumar Dani 5
You can play around "this" operator.