Activity Forums Salesforce® Discussions What is difference between public and global class in Salesforce Apex ?

  • Manpreet

    Member
    April 12, 2017 at 1:32 pm

    Hi suraj,

    Public:
    This means the method or variable can be used by any Apex in this application or namespace.

    Global:
    This means the method or variable can be used by any Apex code that has access to the class, not just the Apex code in the same application. This access modifier should be used for any method that needs to be referenced outside of the application, either in the SOAP API or by other Apex code. If you declare a method or variable as global, you must also declare the class that contains it as global.

     

    A good example of the use of global is in Batch Apex.  Access to running an Apex job can be administered; likewise, an administrator executing the job can do so within the context of any application.

    Thanks.

Log In to reply.

Popular Salesforce Blogs

Popular Salesforce Videos