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

Logging as Guest User Fails #145

Closed
mykah89 opened this issue May 10, 2021 · 7 comments · Fixed by #152
Closed

Logging as Guest User Fails #145

mykah89 opened this issue May 10, 2021 · 7 comments · Fixed by #152
Labels
Type: Bug Something isn't working

Comments

@mykah89
Copy link

mykah89 commented May 10, 2021

Apologies in advance, I'm relatively new to Salesforce development, I recently began using the logger successfully but I think I may have quickly come across an edge case.

Perhaps an obscure requirement but I'm looking to log from a public site with a @RestResource endpoint, I'm getting the following error when I trace the Automated Process user.

field integrity exception (Guest users cannot be record owners.)

It makes sense as to why I'm getting the error, but I was wondering if there was any work around here?

@mykah89
Copy link
Author

mykah89 commented May 11, 2021

Wanted to quickly follow up on this that I was able to get around this for now replacing the line that sets the log.OwnerId in the LogEntryEventHandler class, obviously this is not ideal if I need to update the Nebula logger, but it will allow me to continue with my use case.

In case anyone is curious I just added an additional custom setting checking for the profile name which was already available from the logEntryEvent.ProfileName__c, and then defaulting back to the Autoprocess User as owner if not.

log.OwnerId = Extended_Logger_Settings__c.getValues('Extended Logger Settings').Guest_Profile_Names__c.Contains(logEntryEvent.ProfileName__c) ? System.UserInfo.getUserId() : logEntryEvent.CreatedById;

FYI unrelated, about 4 lines below, this line of code sets the log's SessionId is set twice.

        log.SessionId__c = logEntryEvent.SessionId__c;
        log.SessionId__c = logEntryEvent.SessionId__c;

I would still very much appreciate an alternative work around that may be more suitable, if one exists.

@jongpie jongpie added the Type: Bug Something isn't working label May 11, 2021
@jongpie
Copy link
Owner

jongpie commented May 11, 2021

Hi @mykah89 thanks for reporting this! I think your workaround of setting the record owner to the 'Automation Process' user (instead of the guest user) makes sense/seems like a great solution - I'll try to fix this sometime within the next few weeks.

@mykah89
Copy link
Author

mykah89 commented May 11, 2021

Thanks for the response.

I'm sure you are well aware already but just in case, In my research it looks like System.UserInfo.userType() may return type guest, which if passed through the call chain would make this a smooth operation.

Thanks again, this library has saved me hours of time already.

@jongpie
Copy link
Owner

jongpie commented May 11, 2021

Thanks @mykah89 - If System.UserInfo.userType() returns the guest type, then that seems like a great way to handle it. I'll play around with this more ASAP and will let you know once I have a fix ready.

Glad to hear that the logger has been helpful & saved you time! If you find any other bugs or have any suggestions for new features, just let me know!

@jongpie
Copy link
Owner

jongpie commented May 26, 2021

@mykah89 I've merged a fix for this to the main branch - there is now also an unlocked package that you can use, the latest release v4.4.3 contains this bugfix.

Let me know if you have any other issues!

@mykah89
Copy link
Author

mykah89 commented May 26, 2021

This is great, much appreciated, I had to refactor some of the calls I was using that used Topics, but other than that I was able to install the Unlocked Package right over the deployed metadata without issue.

Thanks again.

@jongpie
Copy link
Owner

jongpie commented May 26, 2021

@mykah89 glad you were able to successfully switch to the unlocked package! And I'm hoping to spend some more time expanding the functionality for Topics - hopefully within the next few weeks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: Bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants