+ Start a Discussion
Kyriacos TheohariKyriacos Theohari 

New Button on Account Object

I need to create a button on the account object that adds the users name to a custom field which is a lookup field to the user object. This field is similar to the account owner field
Best Answer chosen by Kyriacos Theohari
SFDC_DeveloperSFDC_Developer
Create a new javascript button on Account object and use below code.
Here in place of Users__c, you need to use your field name
 
{!REQUIRESCRIPT("/soap/ajax/29.0/connection.js")}
{!REQUIRESCRIPT("/soap/ajax/29.0/apex.js")}

// identify the record
var a = new sforce.SObject("Account");
a.id = "{!Account.Id}";
 
// Get the user Info
var user = sforce.connection.getUserInfo();
// make the field change
a.Users__c = user.userId;
 
// save the change
sforce.connection.update([a]);
 
//refresh the page
window.location.reload();