You don't need to check every field that you query. The issue really boils down to who manages security for the field -- your app or the admin. With standard objects, the answer is always the admin. With custom objects, it depends on whether the field is user visible and is used by users or whether it is internal and used only by your app. Things like wizard state, Auth state, etc.
The standard example would be something like an app that manages contracts. The text of the contract would be managed by the admin, but something like contract state would be managed by your app.
Because this is fundamentally ambiguous, you can make a false positive document outlining which fields are managed by your app and which are not. The worst thing to do is nothing and let the tester try to guess, as they might not have much time to go through your app and may not understand your app well enough to correctly classify this on their own. So a lot of this is up to you in making the case that you own some objects and not the admin.
Once you have the list of fields you need to check perms for, it doesn't matter whether they are used in WHERE clauses or directly accessed -- you need to make sure that the perms are checked. You can use the ESAPI API which contains helper functions such as updateAsUser(), you can write your own helper functions, or you can do checks centrally in your controller.
Triggers run after other code or the UI already allows an operation, so the trigger wouldn't fire if the user didn't have permission already, assuming all the upstream checks are made when necessary. Therefore triggers that only update the object being modified generally don't need a check, the issue is if the the trigger modifies some other object, in which case you do need to do the check if the object is managed by the admin.
For background/async/scheduled jobs, there is absolutely no difference in security requirements for async apex versus synchronous apex. Whether you do an operation synchronously or not has nothing to do with whether the admin's policies need to be respected. The same concerns apply as above -- do the check if you don't own the object and don't do it if you do.
One thing to keep in mind here is that unlike sharing, you generally control the profiles and permission sets of your users as you can package these with your app. So package the permissions so that your checks always return true. Then, if your checks return false, it means that the admin assigned a different perm set or changed the perm set assignment for a user of your app, which is something that should generally result in a failure message. There may be situations in which the app should not work for a user -- say the admin removed some perms from that user, but due to not having deep knowledge of how your app works, did not remove that user from your app. Making these checks is exactly for this type of conflict situation, and generally you want to stop processing with an error message and let the admin resolve the inconsistency at the perm level, rather than trying to guess what the admin would want to do and then override the org perms. This is because if every app overrode the org perms, then the admin wouldn't be able to manage permissions centrally anymore.
There are often situations where there's a one-off use case where a user persona needs access to data but they shouldn't have blanket access to those objects/fields via OLS/FLS.
When reviewing the code from a security perspective static analysis tools such as PMD are often used. If it is really appropriate in this case for the Guest User to have access to this data (but they shouldn't have Profile / Permission Set based access to the fields across the board), you could do the following
Add a NOPMD suppression comment that explains why OLS/FLS is not enforced on the particular query. This helps security reviewers understand why you made the decision and evaluate whether or not it's safe. For example
// NOPMD: Specific CRM data is displayed to the Guest User in this case, but is limited in scope using query filters. Guests should not have Profile-level access to these objects.
Evaluate the situation as a whole to make sure the reasoning around the exception being secure is sound. Check out the sharing defaults and which records could potentially be displayed to the guest. Remember that some fields on Account/Contact can in some cases represent business/competitive information or PII
If this query is flagged during security review, be open to reconsidering the finding in case there really is a security issue that needs to be addressed there.
If you are certain it is a false positive, and have justification for it being secure, you can respond as false positive (see ISV Guide: Responses to False Positives)
Best Answer
So
Yes its of course possible you can do it in two ways (which essentialy are the same)
and
That will check actually even 3 things
Also remember about
with sharing
andwithout sharing
for classWith sharing checks if the user have access (read, read/write, none) to a RECORD and not object itself. So even if user have access to edit fields/object but doesnt have access to record, that user wont be able to edit record.
There are of course cases when user have view all/modify all on object or view all data/modify all data (system admins).
Without sharing ommits that restrictions but it needs to be used only when you have that kinda specific requirement