1

I do not understand how the get;set; and get(); flow together. I am trying to gather values from a url. I keep getting the Compile Error: Unexpected Token: '='. Furthermore, how would I even test the get;set;? I am lost.

public class tablestagingfieldsController {

    public ApexPages.StandardController controller;

    public tablestagingfieldsController(ApexPages.StandardController controller) {
    this.controller = controller;
    }


    public table_staging__c i{get;set;}

    i.name = ApexPages.currentPage().getParameters().get('name');
    i.Reservation__c = ApexPages.currentPage().getParameters().get('resid');

    public PageReference saveanddirect() {
    PageReference a = new PageReference('google.com');
    a.setRedirect(true);
    return a;

}}

1 Answer 1

3

The i.name = ... and i.Reservation__c = ... need to be inside a method or the constructor.

The:

public table_staging__c i{get;set;}

just automatically provides a geti() method and a seti(...) method which Visualforce expects to use to access Apex data. See the Apex Properties documentation for a full description.

In a test you can just assign to i or from i just like you would any other field in the class.

(Better to choose a more meaningful name than i.)

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .