• #25207
    Salesforce | Ankit Ankit #18
    Forcetalks

    Why Salesforce batch apex class and methods using global keyword?

    Global keyword in batch apex

    Tagged: , , , , , ,

    #25215
    Salesforce | Saurabh Saurabh #24
    Forcetalks

    Hello Ankit

    A Database.Batchable class has to be a top-level class (not an inner class) but can now be public.

    When Database.Batchable was first available, implementors had no choice but to use the globalaccess modifier. For people creating managed packages, this had the very unfortunate consequence of making any Database.Batchable part of the managed package’s API whether you wanted it to be or not. global makes a class usable by code outside of a managed package; public makes a class usable by any class within the managed package or within a non-packaged set of source code.

    This error has been corrected so that you now have the choice of making the Database.Batchable public or global and public is the right choice most of the time. Unfortunately I don’t think the documentation has been updated.

    private not global or public is the right access modifier for fields most of the time. Sometimes final is helpful in communicating intent to the reader and/or enforcing its constraint. But a more important point about fields in a Database.Batachable implementation class is that state is not maintained in fields between invocations of the methods unless the implementation class is also marked as Database.Stateful.

    Hope it helps

    Thanks

     

Viewing 2 posts - 1 through 2 (of 2 total)

Please to reply to this topic.

CONTACT US

We're not around right now. But you can send us an email and we'll get back to you, asap.

Sending

About Us

Forcetalks is a Salesforce collaboration platform for coders & developers, geeks & nerds, consultants & business heads, admins & architects, managers & marketers and of course the business owners. A community where you can learn from, where you can contribute to. For you. For Salesforce. Read More...

Copyright 2018 Forcetalks. All Right Reserved.

Log in with your credentials

or    

Forgot your details?