Create and update records using Javascript button in Salesforce- Ajax Toolkit

On this blog we have already seen “how to use Ajax Toolkit to mass update records” without writing any Apex code. In this article as well, we will use Ajax Toolkit to add custom button in Account page layout and update record.

There are endless possibilities and use-cases where this approach can be very useful in Salesforce projects and can be accomplished by Salesforce admins. Lets say we want to create child record on click of button, Update current record on basis of some logic, Update hidden fields, execute existing Apex code using Javascript and so on. All of these can be implemented wthout writing single line of Apex code, Trigger or Visualforce pages.

In this post, we will add custom button on Account detail page and execute Javascript to update Account name using Ajax toolkit. This is just proof of concept and any other field can be updated.

Creating Custom button :

Navigate to “Customize | Accounts | Button, Links and Actions”.

Create new button of type “Detail Page Button” , behavior “Execute Javascript” and content source “Onclick JavaScript”.

Update Record using Javascript

Update Record using Javascript

Create Simple Mass Delete Button for ListView using Salesforce Ajax Toolkit

In Many situation, I needed a Mass Delete Kind of button. Where, i can select records in ListView and simply click “Delete” button.

In this example, we will create a simple List View button and add on “Search Layout” of that object.

Salesforce Mass Delete Button - List View
Salesforce Mass Delete Button – List View

So, create a new Custom Button with following property:

  1. Display Type :  List Button
  2. Behavior : Execute JavaScript
  3. Content Source :  OnClick JavaScript

and use below Source code: