Activity Forums Salesforce® Discussions What Is Property In Salesforce Apex? Explain With Advantages? Reply To: What Is Property In Salesforce Apex? Explain With Advantages?

  • shariq

    Member
    September 20, 2018 at 3:09 pm

    Hi,

    Apex mainly consists of the syntax from the well known programming language Java. As a practice of encapsulation in java we declare any variable as private and then create the setters and getters for that variable.

    private String name;

    public void setName(String n)

    {

    name = n;

    }

    public String getName()

    {

    return name;

    }

    However, the Apex introduced the new concept of property from language C# as shown below:

    public String name {get; set;}

    As we can see how simple the code is and instead of using nearly 8 to 11 lines all done in 1 line only. It will be very useful when lots of member is declared in Apex class. It has another advantage in “number of lines of code” limit by salesforce which will drastically reduced.

    Thanks