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
Bhola VishwakarmaBhola Vishwakarma 

Insert data in object on click of button

Please can anybody tell me that how to send data to object after clicking on button of the visualforce page...

Just guide me whether setter & getter property are required by the controller class & then it is transffered to the object by DML query....Not getting my self clearly so please guide me quickly..

Please reply me urgently & I am w8ting...

kiranmutturukiranmutturu

you have the standard controller with you in that page..?

Dskvap.ax969Dskvap.ax969

 Hi Bhola Vishwakarma,

This is very simple...

 


For example:

 

Just add this in the save function 

database.saveresult binsert = database.insert(b,false);

 

Before doing this you should create instance for the object.

In the above line of code b is object instance

anil.ax822anil.ax822

Hi,

 

As per my uderstanding related to your posting how to insert data in object onclick of button can be achieved by 2 ways.

 

1)by using custom controller and VF pages

2)using ajax

 

public with sharing class accountinsert {

public String no { get; set; }

    public String names { get; set; }



    public PageReference save() {
    
    Account a=new Account(Name=names,AccountNumber=no);
    
    insert a;
    
        return null;
    }

    
}

 

  • VF Page:

<apex:page controller="accountinsert">
<apex:form >
<apex:pageBlock >
<apex:pageBlockSection >
Name:<apex:inputText value="{!names}"/>
Account Number:<apex:inputText value="{!no}"/>  
<apex:commandButton action="{!save}" value="Save" id="theButton"/>

</apex:pageBlockSection>
</apex:pageBlock>
</apex:form>
</apex:page>

 

 

 

Bhola VishwakarmaBhola Vishwakarma

Hiii ....Dskvap

As you told, I understood that how it will get insert record but the fact which i am not getting is that what is binsert & of which object b is instance....

Can u elaborate your things fully...

Your help is appreciate the most...

Regards...

Malika Pathak 9Malika Pathak 9

Hi Bhola Vishwakarma,

please find the solution

yes getter setter property is required 

Apex class

public with sharing class contactinsertData {

public String no { get; set; }

    public String names { get; set; }

  public PageReference save() {
    
    contact c=new contact(LastName=names);
    
    insert c;
    
        return null;
    }
}

VF

<apex:page controller="contactinsertData">
<apex:form >
<apex:pageBlock >
<apex:pageBlockSection >
LastName:<apex:inputText value="{!names}"/>
  <apex:commandButton action="{!save}" value="Save" id="theButton"/>
</apex:pageBlockSection>
</apex:pageBlock>
</apex:form>
</apex:page>
 

If you find this solution is helpful for you please mark best answer