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
KbhaskarKbhaskar 

sample custom form err

hi,
i trying to create a custom form using vf page .can you correct this code .
public with sharing class myClass {

     public String thetextInput1 {get;set;} 
     public String thetextinput2 {get;set;} 

      public void saveObject(){

        myObj regestration_form= new myObj(); 

        myObj.Name__c  =  thetextInput1 ;  
        myObj.roll_num__c =  thetextInput2;  

        insert  myObj; 

      }  

}

Error: Compile Error: Invalid type: myObj at line 8 column 38



vf page 
<apex:page title="reg form"  controller="myclass"  showHeader="false" sidebar="false"   >
 
 
  <apex:form>
    
    <apex:OutputLabel value="Name"   for="thetextInput1"/>
<apex:inputText value="{!thetextInput1 }"  id="thetextinput1"/>
    
  <apex:OutputLabel value="roll no"   for="thetextInput2"/>
<apex:inputText value="{!thetextinput2}"  id="thetextinput2"/>  
    
    <apex:commandButton value="Save" action="{!saveObject}" />
  </apex:form>
</apex:page>



 
Meryem FRQMeryem FRQ
Hi,

Did you create the myObj on your salesforce instance ?
 
ManojjenaManojjena
Hi ,
Try to replace myobject with myobj__c or the object in which you want to create record .
 
public with sharing class myClass {
     public String thetextInput1 {get;set;} 
     public String thetextinput2 {get;set;} 
     public void saveObject(){
		myObj__c regestration_form= new myObj__c(); 
		regestration_form.Name__c  =  thetextInput1 ;  
		regestration_form.roll_num__c =  thetextInput2;  
		insert  regestration_form; 

      }  
}

Try with above code and let me know if it helps .

Thanks 
Manoj
ManojjenaManojjena
Hi ,

You can try like below which will help you with less variable .
 
<apex:page title="reg form"  controller="myclass"  showHeader="false" sidebar="false"   >
	<apex:form>
		<apex:OutputLabel value="Name"   for="thetextInput1"/>
		<apex:inputText value="{!regestration_form.Name__c }"  id="thetextinput1"/>
		<apex:OutputLabel value="roll no"   for="thetextInput2"/>
		<apex:inputText value="{!regestration_form.roll_num__c}"  id="thetextinput2"/>  
		 <apex:commandButton value="Save" action="{!saveObject}" />
	</apex:form>
</apex:page>
public with sharing class myClass {
    public myobject regestration_form{get;set;}
	 public myClass(){
	   regestration_form= new myObj__c(); 
	 }
     public void saveObject(){
		insert  regestration_form; 
     }  
}

Let me know if it heps .