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
Ravindar AdminRavindar Admin 

how to edit and update a custom object dynamically using button in visualforce page?

Hi, I am trying to update the record in visualforce page with a custom button, how to edit and update a custom object record dynamically.

Apex class:

public class ProfileEditPageController { public object__c ro{set;get;} public ProfileEditPageController(ApexPages.StandardController stdController) { ro=new object__c(); ro=[SELECT name,field__c,Department__c,District__c,Email_Id__c,Employee_Id__c, First_Name__c, Mandal__c, Mobile__c, State__c, User__c, Village__c, Ward_Number__c From object__c where user__r.username=:UserInfo.getUsername()]; } public void updateData() { ro.name="sam" update ro; } }​


Visualforce page:

<apex:page standardController="object__c" extensions="ProfileEditPageController"> <apex:form > <apex:pageBlock > <apex:pageBlockSection title=" Details" columns="2"> <apex:inputField value="{!ro.User__c}"/> <apex:inputField value="{!ro.Employee_Id__c}"/> <apex:inputField value="{!ro.First_Name__c }"/> <apex:inputField value="{!ro.name}"/> <apex:inputField label="Email" value="{!ro.email_id__c}" /> <apex:inputField value="{!ro.Mobile__c}"/> <apex:inputField value="{!ro.State__c}"/> <apex:inputField value="{!ro.District__c}"/> <apex:inputField value="{!ro.Mandal__c}"/> <apex:inputField value="{!ro.Village__c}"/> </apex:pageBlockSection> <apex:pageBlockButtons> <apex:commandButton value="Edit" action="{!save}" id="editButton" /> <apex:commandButton value="update" action="{!updateData}" id="saveButton" /> <apex:commandButton value="Cancel" action="{!cancel}" id="cancelButton" /> </apex:pageBlockButtons> </apex:pageBlock> </apex:form>
GauravGargGauravGarg
Hi Ravindar,

Can you please explain the problem you are facing while running this code.

Thanks,
Gaurav
Skype: gaurav62990