Activity Forums Salesforce® Discussions What is the difference between set and private set in Salesforce?

  • Anjali

    Member
    August 27, 2018 at 5:40 am

    Hi Shradha,

    Setter pass user-specified values from page markup to a controller. Any setter methods in a controller are automatically executed before any action methods.

    Private setter means the variable can be set inside the class in which it is declared in. It will behave like readonly property outside that class's scope. Read only property can only be accessed, not mutated. No exception.

     

  • shariq

    Member
    September 19, 2018 at 12:35 am

    Hi,

    Please go through the example.

    Example:

    global virtual class PropertyVisibility {
       // X is private for read and public for write
       public integer X { private get; set; }
       // Y can be globally read but only written within a class
       global integer Y { get; public set; }
       // Z can be read within the class but only subclasses can set it
       public integer Z { get; protected set; }
    }

    Hope this helps.

Log In to reply.

Popular Salesforce Blogs

Popular Salesforce Videos