function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
AvLavAvLav 

Problems with get set testing.

Hy everybody!

 

I have some problem with the {get; set} formulas. Here is an example:

 

/* CODE IN MYCONTROLLER CLASS*/
String exampleString {get;set}
...

 

So, If I want to use the set method with a parameter, for example:

 

/* CODE IN MYCONTROLLERTESTMETHOD */
mycontroller controller = new mycontroller();
controller.setExampleString('TestString');

I got an error.

 

What does it mean exatly: {get;set}?

 

 

 

Best Answer chosen by Admin (Salesforce Developers) 
bob_buzzardbob_buzzard

This syntax is used for automatic properties.

 

To test the setter, you simply assign a value:

 

controller.exampleString='MyExample';

 

To test the setter, you simply read it:

 

String str2=controller.exampleString; 

 

There's more detail in the Apex Developer's Guide on page 97.

All Answers

bob_buzzardbob_buzzard

This syntax is used for automatic properties.

 

To test the setter, you simply assign a value:

 

controller.exampleString='MyExample';

 

To test the setter, you simply read it:

 

String str2=controller.exampleString; 

 

There's more detail in the Apex Developer's Guide on page 97.

This was selected as the best answer
AvLavAvLav

Thanks your answer, you're right.
It's very simple (as you write: controller.exampleString=''MyExample') if you use the public access modifier. But my variable is private.

So I will change the modifier.

bob_buzzardbob_buzzard
You can mark it as a solution if you like - that way it may help others.