website logo

Insert , Update data in salesforce Custom Object

create visualforce page by clicking on Build->Develop->Visualforce page
click on new button for creating new form

new visualforce page creation

enter Label and Name of visualforce page and write code for creating form and click on save button for saving created page.

<apex:page docType="html-5.0" showHeader="false" sidebar="false" standardStylesheets="false" controller="saveuser">
<apex:form >
<fieldset data-role="fieldcontain">
<label for="name">Name:</label>
<apex:inputText id="name" value="{!name}" />
<fieldset data-role="fieldcontain">
<label for="address">address:</label>
<apex:inputText id="address" value="{!address}" />
<fieldset data-role="fieldcontain">
<label for="dob">DOB:</label>
<apex:inputText id="dob" value="{!dob}" />
<apex:commandButton id="submit-3" value="Submit" action="{!submit}" oncomplete="redirectBack()" />

submit visualforce form

On submit click we Pass data to controller and controller execute query like insert , update and after insert or update redirect to visualforce page .

For insert or up date we need a custom object so first create custom object
For creating custom object go to Build->Create->Object and click on new custom object button.

insert data in custom object

use setter and getter for set and get value of visualforce page.setRedirect use for redirect to new visualforce page after insert or update custom object.

public with sharing class user{
public String name{get;set;}
public String address{get;set;}
public String dob{get;set;}
public PageReference save() {
mypackp__name__c user=new userlog__c(mypackp__name__c=name,mypackp__address__c=address, mypackp__dob__c=dob);
PageReference pagr= Page.saveuser;
return pagr;
catch(System.DMLException e)

for update first select row of custom object that's you want to update like
mypackp__name__c user=(SELECT mypackp__address__c,mypackp__name__c FROM userlog__c where mypackp__dob__c=dob);
and set field to update
update user;