How to save the value of a form in custom object of salesforce

my apexpage and controller is

<apex:page Controller="test_validation">
  <apex:form >
      <apex:pageBlock >
          <apex:pageblockButtons>
              <apex:commandButton action="{!Save}" value="Save"/>
          </apex:pageblockButtons>

          <apex:pageBlockSection>
              <apex:inputField label="Summary" value="{!testvalidation.Sumary__c}"/>
              <apex:inputField value="{!testvalidation.Class__c}" label="Class"/>
          </apex:pageBlockSection>  
                </apex:pageBlock>
  </apex:form>
</apex:page>

public class test_validation {
    public test_validation__c testvalidation{get;set;}
    public test_validation__c vartest{get;set;}

    public PageReference Save(){
        vartest=new test_validation__c();
        vartest.Sumary__c=??????
        vartest.Class__c=??????
        insert vartest;
        return null;
    }
}

i want to know how to access vf input field in apex class.

Answers:

Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

You save the same instance that the Visualforce page is bound to. When the form is submitted the platform updates the fields and then you can save the instance:

public class test_validation {
    public test_validation__c testvalidation{get;set;}
    public test_validation() {
        testvalidation = new test_validation__c();
    }
    public PageReference Save(){
        insert testvalidation;
        return null;
    }
}

This Visualforce Workbook explains this and many other important concepts.


All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x