-
-
Notifications
You must be signed in to change notification settings - Fork 168
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
Add setDatabaseResult(EmptyRecycleBinResult) and setDatabaseResult(List<EmptyRecycleBinResult>) #806
Conversation
WIP - unit tests needed! |
@@ -140,15 +140,15 @@ LogEntryEventBuilder | |||
|
|||
The same instance of `LogEntryEventBuilder`, useful for chaining methods | |||
|
|||
#### `setDatabaseResult(Database.LeadConvertResult leadConvertResult)` → `LogEntryEventBuilder` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Swapped with DeleteResult
to maintain alphabetical order.
Similar changes in other classes.
@TrangOul overall this looks great! I think having completeness of all of the
There are also a couple of steps that I'll have to manually run to generate the new package version, so if you'd like any help wrapping up the unit tests/anything else, just let me know! |
@jongpie, how do you generate unit tests? Right now you have 2 message formats × 7 logging levels × 7 Database Results (some tests are still missing - |
@TrangOul great question - I used to have some macros/keyboard shortcuts to help me with writing those test methods in In the meantime, I really appreciate you working on the tests - I'm working on reviewing your latest changes, and I'm hoping I can merge & release this either later this week or next week. |
@TrangOul I saw you pushed a few more commits - let me know if you're planning to push any more changes. |
@jongpie if it's blocking you (because of more code to review), I won't push more for now. I'll just create a new PR for subsequent changes (if any). |
@TrangOul that would be great - I'd like to get this merged ASAP so I can also finish a few other releases this week. But if there are any other changes that you'd like to still push to this branch first, please let me know, and I can review/merge it when you're done. At the moment, there are several test failures in |
@jongpie , I think I'm done for now. |
…ying to split & parse an Apex source snippet of Logger_Tests I've "fixed" it by ignoring Logger_Tests as an origin using Logger.ignoreOrigin(), which avoids the source snippet code from running in LogEntryHandler
…e.EmptyRecycleBinResult
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@TrangOul this is ready to go! I'm working on merging & releasing this now 🥳 I've added some commits with a few changes:
- Fixed some test failures in
Logger_Tests
- Some failures were easy fixes due to some very small issues in the setup of some of the new test methods
- A few of the failures were happening in existing test methd (related to saving date via
saveLog()
), caused by some downstream exceptions within the classLogEntryHandler
. It's something I'll revisit in the future to optimize, but for now, I made a few quick workarounds in theLogger_Tests
methods to avoid the exceptions
- Added a few more tests in
LogEntryEventBuilder_Tests
for the newDatabase.EmptyRecyleBin
overloads - Reverted some of your changes:
- Reverted casing changes
UserInfo.getUsername()
- Reverted back to
System.now()
andSystem.today()
- Reverted casing changes
- Small scope creep: Fixed some existing code that caused PMD scan violations in newer versions of PMD/sf code analyzer
I've just finished releasing this as release |
@@ -1051,7 +1051,7 @@ global with sharing class LogEntryEventBuilder { | |||
private static void setUserInfoDetails(LogEntryEvent__e templateLogEntryEvent) { | |||
templateLogEntryEvent.Locale__c = System.UserInfo.getLocale(); | |||
templateLogEntryEvent.LoggedById__c = System.UserInfo.getUserId(); | |||
templateLogEntryEvent.LoggedByUsername__c = System.UserInfo.getUserName(); | |||
templateLogEntryEvent.LoggedByUsername__c = System.UserInfo.getUsername(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jongpie, why? It was correct, according to the Salesforce API.
The IDE complains about the current one:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@TrangOul I've never seen that warning in VS Code, but maybe I've disabled whatever option that is - do you know what plugin/feature controls that warning message?
Personally, I've always considered the user of getUserName()
(capital N
) a bug in Apex/Salesforce docs. I think getUsername()
should be considered the correct casing - it's consistent with the rest of the platform, and it provides clarification that it is referring to the "username", and the "user's name".
- Everywhere else in Salesforce (and from what I've seen in other systems too/software engineering in general), it's always spelled
Username
with a lowercasen
. The only place I'm aware of in Salesforce that uses the capitalN
is that method name. And since it returns the value of the fieldUser.Username
, I think the method name should use the same casing.-
User.Username
field has lowercasen
in the field API name, the field label, and the corresponding docs -
Salesforce login pages (including Community Cloud/Experience Cloud, etc) all
-
I've also worked on multiple teams (at different companies) where using getUserName()
is too ambiguous & confusing for people new to Apex (or anyone unfamiliar with the UserInfo
class), occasionally resulting in bugs.
- Some people (incorrectly) thought
UserName
referred to the user's name (i.e., theUser.Name
field that combinesUser.FirstName
andUser.LastName
- Some people (correctly) thought
UserName
referred to the user's username (i.e., theUser.Username
field)
I think both are valid thoughts/guesses with the UserName
casing - Salesforce uses User
as a prefix on large number of standard fields (listed below), so I think there will always, inevitably, be some confusion if getUserName()
refers to User.Name
or User.Username
User.UserRoleId
User.UserType
- 12 fields that with
UserPermissions...
, likeUser.UserPermissionsMobileUser
- 81 fields that start with
UserPreferences....
, likeUser.UserPreferencesUserDebugModePref
But I've personally never had a situation where using getUsername()
is unclear/confusing.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jongpie, I'm using WebStorm with Illuminated Cloud 2. Here are my settings:
Unfortunately, Salesforce is inconsistent when it comes to letter casing. Another example: SObject:
(in my own code I use sobject
at the beginning of the name and SObject
later, for example getSObjectApiName(sobj)
; IMO sObj
looks goofy)
It's even more annoying, since Apex is case-insensitive and such inconsistencies could be fixed in one of the release updated without causing any regression.
I agree with your reasoning that Username
= username (technical) and UserName
= user's name (user-friendly), and I also stick to "username" as a single word in my own class/function/variable names (and also correct them in code reviews).
Nevertheless, I'm sticking to what SF API uses because it simplifies my workflow - I just use automatic formatting (which, obviously, does much more that changing the case).
closes #804