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
sreejasreeja 

dml operation using the bootstrap

public class Personal_Information{
     
      
      
       public list<Personal_Information__c> perinfo{get;set;}
  
   
   
     
       public void  Insertrecord(string name){
       
       
          
            
              list<Personal_Information__c> listperinfo = new list<Personal_Information__c>();
             
                 Personal_Information__c  perinfo = new Personal_Information__c();
          
          
         perinfo .name = name;
          
          
         listperinfo.add(perinfo );
          
          
          
           
           
           if(! listperinfo.isEmpty()){
           
           
           
              insert listperinfo;
           
           }
          
          
          
       
       }
    
  
  
  
  }





visualforce page:



<apex:page controller="Personal_Information" sidebar="false">
  
  
    <html>
      
        <head>
        
         <meta charset="utf-8"/>
  <meta name="viewport" content="width=device-width, initial-scale=1"/>
  <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.0/css/bootstrap.min.css"/>
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
  <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.0/js/bootstrap.min.js"></script>
        </head>
    
      
    
     <body>
     
     
     
        <div class="col-sm-3">
     <div class="form-group">
      <label for="usr">Name:</label>
      <input type="text" class="form-control" id="usr" value ="{!name}" />
    </div>
     </div>
     
     
     <br/>
     
      <button type="button" class="btn btn-success"   action ="{!Insertrecord}" >Save</button>
     
     
     </body>
    
    
 
    
    </html>
  
   
</apex:page>

without use of the salesforce standared fileds, records should have to insert using a custom button , it was not  getting save , any wrong with this??


 
Best Answer chosen by sreeja
Meghna Vijay 7Meghna Vijay 7
Hi,
You cannot pass parameters to method bindings made in your Visualforce page to your controller. So in the controller add it like:-
public class Personal_Information{
  public String name{get;set;} // Binds VF page variable with the controller

 public void insertRecord() {
   // Same as your code.
}

}

If it helps, mark it as solved.
Thanks

All Answers

Meghna Vijay 7Meghna Vijay 7
Hi,
You cannot pass parameters to method bindings made in your Visualforce page to your controller. So in the controller add it like:-
public class Personal_Information{
  public String name{get;set;} // Binds VF page variable with the controller

 public void insertRecord() {
   // Same as your code.
}

}

If it helps, mark it as solved.
Thanks
This was selected as the best answer
sreejasreeja
hi meghna, i had done as peryour , above code, i dont have that much idea about the action function, can you please suggest me  a example ?? it might be helpful .

 thanks 
sri 
sreejasreeja
The above code you had sent was , executed, i am trying with the action function on the custom button for inserting a record in the custom object
Meghna Vijay 7Meghna Vijay 7
Okay. Example for the action function :-
<apex:page controller="Personal_Information" sidebar="false">
   <apex:actionFunction name="saveActionFunction" action="{!insertRecord}">
    <apex:param name="firstParam" assignTo="{!name}"/>
 
<apex:commandButton name="save" onclick="saveActionFunction();"/>
</apex:page>


Controller Class
public class Personal_Information{
  public String name{get;set;}
  
}
Basically in your case it is not that much needed.
For more example see this link:-
https://developer.salesforce.com/forums/?id=906F0000000BTIPIA4
http://salesforceworld.blogspot.com/2011/06/parameter-passing-using.html
Hope it helps, if it does then mark it as solved.
Thanks
 
GovindarajGovindaraj
Hi Vani,

We can't call Apex functions from html. We should go for some VF attributes.

Below is the Action Function example,
<apex:page controller="cmpinfocheck"> 
   function save(){
     actionFunc(); //2.Call the ActionFunction
    }   
	<apex:form id="form"> 
		<apex:inputText value="{!empname}"/>
 		<apex:actionFunction name="actionFunc" action="{!cmpdata}" reRender="form"/> //3.Call the Apex method
		<apex:commandButton value="Save" onclick="save()" /> //1.Call the JavaScript method
	</apex:form> 
</apex:page
Thanks,
Govindaraj.S
sreejasreeja
hi meghna  as u had used the apex commandbutton  and got the code executed, thanks for that , but , i need to use with custom button...


<button type="button"  action ="{!Insertrecord}" >Save</button>

 thanks 




 
sreejasreeja
hi govindraj, i need to save the code, with the custom css button, can you please, 
<button type="button" class="btn btn-success" action ="{!Insertrecord}" >Save</button>
<input type="text" class="form-control" id="usr" value ="{!name}" />
and input should be 
GovindarajGovindaraj
Hi Sree,

We can't call Apex methods directly from HTML. shall we know why do you don't want to use VF tags and need HTMl for this ?