Salesforce Stack Exchange is a question and answer site for Salesforce administrators, implementation experts, developers and anybody in-between. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I know the long hand way of doing this is as follows:

private String var1;

public String getvar1() {
 return var1;
public void setvar1(String str) {
 var1 = 'Prefix '+str;

The shorthand way is something along the lines of the following but I don't know how the value is passed:

public String var1 {
 set(String str) {
  this = 'Prefix '+str;

As such the set is pseudocode. I would like to know the correct form for this shorthand way of writing the setter.

share|improve this question
Refer here...possible duplicate of… – ClassCastException Feb 7 '14 at 12:42
up vote 6 down vote accepted

This should do.

public String var1 {
 set {
  var1 = value; 

You can use 'value', which has the actual input for the setter.

This is clearly described in the documentation

share|improve this answer
Thanks, this works perfectly. I cannot mark this as the answer for another 8 minutes. – Venko Feb 7 '14 at 12:45

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.