You need to sign in to do that
Don't have an account?
want to save data in table
I create a table mytest__c and there is name field in table
i want to save input filed value in name field . so please help me . i create vf page and apex class for this
i create a vf page :
<apex:page controller="myClassController">
<apex:form >
<apex:inputField value="{! mytest1.Name}"/>
<apex:commandButton value="Save" action="{! Save}"/>
</apex:form>
</apex:page>
I create apex class is as fellow :
public class myClassController {
public mytest__c mytest1{get;set;}
public mytest__c mytest() {
mytest1 = new mytest__c();
return mytest1;
}
public PageReference Save(){
//system.debug(mytest1);
mytest1 = new mytest__c();
insert mytest1;
return null;
}
}
So provide me solution
Please try below code it will solve your problem,but you need to add mandatory fields in page .
If this helps you to solve your problem please mark it as best answer. It will help other to find best answer.
What is the function of this line,
public myClassController(ApexPages.StandardController controller)
and what is happend while passing the parameter as ApexPages.StandardController controller
and in the save method why don't you mentioned pagereference in the place of void..
public myClassController(ApexPages.StandardController controller) line is a constructor of taking parameter as standradcontroller instance to use the method in that class .
ApexPages.StandardController , it is like this because the class is in the namesapce ApexPages.
If you add any standradcontroller in your page system will automatically ask you to add one contructor like this .
Returntype PageRefrence you can add if you want, but you need to return som ething from class .
If you want to redirect to ant page you can use pageReference as well
You can check below links for pagereference and Standradcontroller methods .
www.salesforce.com/docs/developer/pages/Content/apex_ApexPages_StandardController_methods.htm
www.salesforce.com/us/developer/docs/apexcode/Content/apex_system_pagereference.htm
Please let meknow any issue .
DEAR Manoj ,
Your code is not working for me
Apart from name is there any required field in your object . How you can check, just create a record from salesforce ui by clicking on the tab .
How may field value you need to enter from there those field you need to keep .
Else better set a debug log and try to check in debug ,if insert fail it wil throw you an exception which you can catch in debug .
Please let me know still you have issue .
Have you tested with salesforce UI .As the standrad validation rule will fire .So you need to add the standrad fields with Name .
is the name is the only one mandatory field in your custom object .Please confirm.
Give a try with the code below.
Thanks,
Kapil