+ 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
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!