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
mskudlarekmskudlarek 

Custom Button on Standard Object

I want to make a custom button that, when clicked, checks a box (a custom field on a standard object) and then saves the record. 

 

Do I have to do that via a visual force page, or can it be through some fancy javascript with that button? Thanks a bunch.

crop1645crop1645

In your custom button - 

* behavior = Execute Javascript

* Content source = 'Onclick Javascript

* Body = 

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

    var fObj = new sforce.SObject("Foo__c");
    fObj.Id = '{!Foo__c.Id}';
    fObj.Status__c = 'Approved';
    var result = sforce.connection.update([fObj ]);

    if (result[0].success=='false') {
         alert(result[0].errors.message);
    } else {
       alert('You have accomplished fie on foo');
       window.parent.location.href="/{!Foo__c.Id}?retURL=%2F{!Foo__c.Id}";
    }