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
xddankexxddankex 

custom button to update a field

hi

 

i have an customobject. i have a view created to show some records. i want to have an ability to update a field in the custom object to true for all selected records<a href="http://www.wbiura.pl"> wirtualne biuro </a>. i have a custom button created and have it included in the view layout

 

I am not sure how to go about doing the update using java script.  i have the behaviour as execute javascript and in onclick javascript i have

	{!Appointment__c.test1__c}='true'

 Test1 is the field which i want to update. check syntax give no errors but when i click the button its gives

A problem with the OnClick JavaScript for this button or link was encountered:

syntax error

 Any ideas, i dont mind using javascript or any other means to do a mass update.

 

Thanks

Navatar_DbSupNavatar_DbSup

Hi,

      Below is the sample code in javascript which triggers on the click on custom button:Tryout this code it may help you.

 

{!REQUIRESCRIPT("/soap/ajax/20.0/connection.js")}
{!REQUIRESCRIPT("/soap/ajax/20.0/apex.js")}
sforce.connection.sessionId = '{!$Api.Session_ID}';
var MailingSObjectID =  '{!test__c.Id}';
var fzb = new sforce.SObject("test__c");
fzb.id = MailingSObjectID;
fzb.testdata__c= true; // Update a field
result = sforce.connection.update([fzb]);
window.location.href =  '{!test__c.Id}';

 Did this answer your question? If not, let me know what didn't work, or if so, please mark it solved. 

Pankaj Kumar Pandey2Pankaj Kumar Pandey2

This will work only for one record not for multiple selected record...

Pankaj Kumar Pandey2Pankaj Kumar Pandey2

You can use this code for Mass update functionality. 

//****************************************************************

{!REQUIRESCRIPT("/soap/ajax/19.0/connection.js")}
var url = parent.location.href;
var records = {!GETRECORDIDS($ObjectType.Account)};
var records = [];

if (records[0] == null) {
alert("Please select at least one record to update.");
} else {
for (var a=0; a<records.length; a++) {
var account = new sforce.SObject("Account");
account.Id = records[a];
account.IsCustomer__c = 'true';
records.push(account);
}
result = sforce.connection.update(records);
parent.location.href = url;
}

 

//****************************************************************