function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Anuj Joshi 42Anuj Joshi 42 

Can batch class be declared other than global?

Hi All,

I have a batch class. When I run the checkmarx report I am getting the Query:sharing issue. I states that:

All entry points to an app (Global or Controller classes) must use the 'with sharing' keyword. Classes without this keyword run without sharing if they are entry points to your code, or with the sharing policy of the caller. Do not omit the sharing declaration as this hides critical security information in side-effects that can change when code is refactored. Only declare classes as 'without sharing' if they are not entry points to your app and if they only modify objects whose security is managed by your code (such as wizard state, or fields in a site). It is a common misconception to believe that batch apex or async apex must run with the global keyword. This is not true, the only classes that must be global are those that expose webservices or are intended to be used by extension packages. All async apex should run as public in order to avoid creating privileged entry points to your app.

I need to remove this issue from the report. Also I have controllers declared as without sharing. How do I resolve this issue for batch classes and controllers defined with without sharing

Thanks,
Anuj
Arunkumar RArunkumar R
Yes. You can also have Public access modifier batch class instead of global. Also, make sure change global access to the public from the start, execute and finish methods.