1

Iam a newbe to APEX and I have the following form and Controller

<apex:page controller="AddLinesController">
  <apex:pageBlock >
  <apex:pageMessages />
  <apex:form >
      <h1>Create Quote for "{!opportunity.Name}" with paste from seema.de</h1>
      <apex:inputHidden id="QuoteId" value="{!opportunity.Id}"/>
      <p>
          <label for="name">Quote Name</label>
          <br/>
          <apex:inputText value="{!name}" id="name" />
      </p>
      <p>
          <label for="paste">Paste from seema.de</label>
          <br/>
          <apex:inputTextarea id="paste" cols="55" rows="3"/>
      </p>
      <p>
         <apex:commandButton action="{!save}" value="Create quote from paste"/>
         <a href="/{!opportunity.Id}">Cancel</a>
      </p>
      Value is: <b>{!name}</b>
  </apex:form>
  </apex:pageBlock>
</apex:page>

An the controller

public class AddLinesController {
    public String opportunityId;
    public String name;
    public String paste;

    public String getName() {
        return name;
    }
    public void setName(String s) {
        name = s;
    }

    public Opportunity getOpportunity() {
        return [SELECT Id, Name FROM Opportunity
                WHERE Id = :ApexPages.currentPage().getParameters().get('OpportunityId')];
    }

    public PageReference save() {
        Opportunity op = getOpportunity();

        Quote q = new Quote(Name=name, OpportunityId=op.Id);
        insert q;

        PageReference page = new ApexPages.StandardController(q).view();
        page.setRedirect(true);
        return page;
    }
}

So far the getOpportunity works fine but the setName does not work why? Why it does not work?

  • 1
    So in save() your local property name is not set when you try to instantiate the Quote? – Mike Chale Aug 3 '13 at 2:26
2
public String name;

public String getname() { //getters 
    return name;
}
public void setname(String name) { //setters 
    this.name = name;
}

try the above and this is the standard way of using getters and setters in apex.

Before your action methods all the setters will run and you can debug the variable in your save method

3

Instead of

public String name;
public String getname() { //getters 
return name;
}
public void setname(String name) { //setters 
this.name = name;
}

we can rite get and setters directly

public String name{get;set;}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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