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:
Hi Suhas,
I think following code would solve your problem:
>> Create a detail page script button and use following code
var optyRec = new sforce.SObject("Opportunity"); 
optyRec.Id = '{!Opportunity.Id}'; 
optyRec.OwnerId = '{!$User.Id}'; 
var result = sforce.connection.update([optyRec]); 
consider the related object is Opportunity
All the best!