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
Phil WaltonPhil Walton 

Build a new Button to update a field

Hi All

Was looking for some tips on building a new button to update a field in Salesforce.

Something like...Button called 'Make this Contact NEW', and when clicked that Contact record Status field is updated to 'NEW'.

Done these before but I can not find my cheatsheets??

Many thanks in advance!!

Phil

Rahul SharmaRahul Sharma

Hey Phil,

 

Add following JS code in your button,

Just update the code accotding to which field to update with value needed.

{!REQUIRESCRIPT("/soap/ajax/23.0/connection.js")}
{!REQUIRESCRIPT("/soap/ajax/23.0/apex.js")}

var ConId = "{!Contact.Id}";
var objContact = new sforce.SObject('Contact');
objContact.Id = ConId;
objContact.Title = "Salesforce Developer";
result = sforce.connection.update([objContact]);
location.reload(true);

 

Phil WaltonPhil Walton

Hey Rahul

Thanks for your response!

Could you highlight which parts I should update with the field name and the custom object name?

Much appreciated!

Phil

Phil WaltonPhil Walton

BTW, here is the attempt I made it tweaking your code...

 

Note the custom object is called "Fulfilment"

The custom Field I want to change is called "Ready to Proceed" (it is a checkbox)

And I want to change this field to be True (i.e. ticked).

 

{!REQUIRESCRIPT("/soap/ajax/23.0/connection.js")} 
{!REQUIRESCRIPT("/soap/ajax/23.0/apex.js")} 

var Fulfilment = "{!Fulfilment__c.Id}"; 
var objFulfilment = new sforce.SObject('Fulfilment__c'); 
objFulfilment__c = Fulfilment; 
objFulfilment__c.Ready_to_Proceed__c = "True"; 
result = sforce.connection.update([Fulfilment]); 
location.reload(true);