Thursday, December 26, 2013

Update Salesforce using JavaScript AJAX Toolkit

For you who are not from developer background, don't be afraid with the title of this blog, this is not about how to write JavaScript blog. But, using a simple script provided with Ajax Toolkit, you can make use of it for your business needs in Salesforce area.

Use Case:
To change Account Type from Prospect to Customer via a button click, and Customer value itself maybe not a picklist in the account type.

Create a custom button in Account object. Here we go:
  1. Navigate to Setup | Customize | Accounts | Buttons, Links, and Actions
  2. Click New Button or Link, select Detail Page Button in Display Type, and in Behavior select Execute JavaScript
  3. Paste script below
  4. Add custom button created to the Account page layout.
  5. Done - simple ?
The script:
 var AccObj = new sforce.SObject("Account");  
 AccObj.Id = '{!Account.Id}';  
 AccObj.Type = 'Customer';  
 var result = sforce.connection.update([AccObj]);  

Further tweak, you also can differentiate Customer record type with Prospect record type, so in the script above, add one line to change Account Record Type with Customer Record Type Id, then assign different Page Layout for Customer.

No comments:

Post a Comment

Page-level ad