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
Manish DeshmukhManish Deshmukh 

How to write a visualforce page to update field through javascript onclick of custom button

suriya deepaksuriya deepak
Hi manish ,

You can create custom button in object without go for visualforce page . and u can use javascript for that button  juz ill give small example to update field value using custom button (javascript button)

open oppurtunity obejct - Custom Button or Link - create new button - on click javascript option will be tere .!!!! after use below code to update field value while click that button.


var newRecords = []; 

var c = new sforce.SObject("Opportunity"); ="{!Opportunity.Id}"; 
c.CloseDate = new Date(); 

result = sforce.connection.update(newRecords); 


            I have created  custom button on Account page
    In OnClick JavaScript    write this code:
                                                               window.location = 'apex/updatefield';
updatefield is the  name of vf page.
vf page:
<apex:page standardController="Account">
                Account name:<apex:inputField value="{!Account.Name}" />
                <apex:commandButton value="Save" action="{!save}" />

Hope this helps.