Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Exception when Request.getCurrent().getRequestId() is null #67

Closed
mikbranchaud opened this issue Nov 21, 2022 · 4 comments
Closed

Exception when Request.getCurrent().getRequestId() is null #67

mikbranchaud opened this issue Nov 21, 2022 · 4 comments
Labels
bug Something isn't working
Projects
Milestone

Comments

@mikbranchaud
Copy link

Describe the bug
I have seen intermittent occasions where this line (rflib_DefaultLogger.reportLogs) errors:
Request_ID__c = requestId.substring(0, Math.min(requestId.length(), 40)),

with:
System.NullPointerException: Attempt to de-reference a null object

The first time it happened it was only in my sandbox and I made a temporary change to set Request_ID__c another way but just figured it was a fluke. This is now occurring in our shared dev environment so there seems to be some combination of circumstance that leads to this

Seems to only be occurring right now on one particular trigger which is on the User record (I dont remember the trigger this occurred on the first time)

Version
What version are you using? Did you make any modifications to the code?

Code Snippets
String requestId = Request.getCurrent().getRequestId();
rflib_Log_Event__e eventToLog = new rflib_Log_Event__e(
Request_ID__c = requestId.substring(0, Math.min(requestId.length(), 40)),
Log_Level__c = logLevel.toString(),
Context__c = context.substring(0, Math.min(context.length(), 40)),
Log_Messages__c = messageSize < MAX_MESSAGE_SIZE
? maskedLogMessagesIfApplicable
: maskedLogMessagesIfApplicable.substring(messageSize - MAX_MESSAGE_SIZE)
);

Expected behavior
I dont know why Request.getCurrent().getRequestId() would be null but if there is a setting I need to make to make it never null, or a backup to generate a unique Id on the occasion it is null

Screenshots
If applicable, add screenshots to help explain your problem, i.e. Chrome Dev Console.

@mikbranchaud
Copy link
Author

Not sure if this helps, but I have a trigger on the User record to do something and I have logger entries in the class that does it. This usually works fine when an admin updates a user record through setup. But I recently exposed the field that triggers this class on Advanced User Details so user can edit this field themselves. This is when the error is seen so not sure if saleforce is doing something weird here.

@mikbranchaud
Copy link
Author

@j-fischer
Copy link
Owner

Hi @mikbranchaud ,

Sorry for the late reply, December was extremely busy and I had no time to pay attention to the library. The issue that you reported seems off to me and I think it would be good to open a ticket with Salesforce about it. It is my understanding that the Request ID should never be NULL, so I would be interested to know under what circumstances that would be legit?

Here is the documentation for reference, it does not indicate that the value could be NULL: https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_class_System_Request.htm#apex_System_Request_getCurrent

Either way, I will update the logger to handle this edge case and will add "NULL" as a string if the request ID is not available.

I am close to finishing another feature shortly. The fix should be ready before returning to work in the coming year.

Thanks again for your message and using the framework!

Cheers,
Johannes

@j-fischer j-fischer added the bug Something isn't working label Dec 30, 2022
@j-fischer j-fischer added this to To do in RFLIB-FS via automation Dec 30, 2022
j-fischer added a commit that referenced this issue Dec 30, 2022
…ch causes a NullPointerException in the default logger. If the request ID is null, a "NULL" string will be used as the request ID instead.
@j-fischer j-fischer removed this from To do in RFLIB-FS Dec 30, 2022
@j-fischer j-fischer added this to To do in RFLIB via automation Dec 30, 2022
@j-fischer j-fischer added this to the RFLIB 4.1 milestone Dec 30, 2022
@j-fischer j-fischer moved this from To do to In progress in RFLIB Dec 30, 2022
@j-fischer j-fischer moved this from In progress to Done in RFLIB Dec 31, 2022
@j-fischer
Copy link
Owner

Releases 4.1 has been published. Thanks for submitting this issue

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
RFLIB
  
Done
Development

No branches or pull requests

2 participants