From 33100dd37d0b718620fefbc580d106645983361f Mon Sep 17 00:00:00 2001 From: Suyash More Date: Mon, 16 Dec 2024 18:06:25 +0530 Subject: [PATCH] Handle exception triggered by inactive user when calling getUserName() Wrap UserInfo.getUserName() in a try/catch block to handle exceptions when the code runs in the context of an inactive user. --- force-app/tdtm/classes/TDTM_ObjectDataGateway.cls | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/force-app/tdtm/classes/TDTM_ObjectDataGateway.cls b/force-app/tdtm/classes/TDTM_ObjectDataGateway.cls index 798f718cc46..e6d57941158 100644 --- a/force-app/tdtm/classes/TDTM_ObjectDataGateway.cls +++ b/force-app/tdtm/classes/TDTM_ObjectDataGateway.cls @@ -66,13 +66,18 @@ public without sharing class TDTM_ObjectDataGateway implements TDTM_iTableDataGa **/ public static List getClassesToCallForObject(String objectName, TDTM_Runnable.Action action) { String strAction = action.Name(); - String currUserName = UserInfo.getUserName(); + String currUserName; + try{ + currUserName = UserInfo.getUserName(); + }catch(Exception e){ + currUserName = null; + } List listClasses = new List(); for (Trigger_Handler__c th : listTH) { Set excludedUserNames = (th.Usernames_to_Exclude__c != null ? new Set(th.Usernames_to_Exclude__c.toLowerCase().split(';')) : new Set()); if (th.Object__c == objectName && th.Trigger_Action__c != null && th.Trigger_Action__c.contains(strAction) && th.Active__c == true - && !excludedUserNames.contains(currUserName.toLowerCase())) { + && (currUserName != null && !excludedUserNames.contains(currUserName.toLowerCase()))) { listClasses.add(th); } }