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
Suhas GB 4Suhas GB 4 

Custom button on the details page of a object such that when we click it should update a field on the related object. Can anybody please how we can implement this in salesforce

James LoghryJames Loghry
Hi there,

You'll want to take a look at object-specific quick actions, which should help meet your requirement.  There are a few different trailhead modules on quick actions to get you started, including this one: https://trailhead.salesforce.com/en/projects/quickstart-devzone-app/steps/devzone-app-3
Dev-FoxDev-Fox
Hi Suhas,
I think following code would solve your problem:
>> Create a detail page script button and use following code
{!REQUIRESCRIPT("/soap/ajax/29.0/connection.js")} 
var optyRec = new sforce.SObject("Opportunity"); 
optyRec.Id = '{!Opportunity.Id}'; 
optyRec.OwnerId = '{!$User.Id}'; 
optyRec.stagename='Closed';
var result = sforce.connection.update([optyRec]); 
location.reload(true);
consider the related object is Opportunity
All the best!