Please reload

Recent Posts

How To Dip Your Toe Into Salesforce.com Javascript

July 13, 2017

If you are staying with Salesforce.com Classic, JavaScript is a great tool, but getting started can be intimidating.  At least for me it was. You build a button, Salesforce.com lets you save it, and then, you get an obscure ‘undefined token’ error.

 

I’ve found the best way to start learning is to start simple.  Create a button to do one action like update a checkbox on the record.

 

Requirements:

  • Create a checkbox field (‘Activate_Button_Checkbox__c’)

  • Get your object name (‘Account’). 

  • Substitute your checkbox field name and object name into the code below.

 

{!REQUIRESCRIPT("/soap/ajax/20.0/connection.js")} 
var newRecords = [] 
var A = new sforce.SObject("Account"); 
a.Id = "{!Account.Id}"; 
a.Activate_Button_Checkbox__c = 1; 
newRecords.push(a) 
result=sforce.connection.update(newRecords); 
window.parent.location.href="{!Account.Id}"

 

 

Clickpath: Salesforce Setup/Accounts(Object)/Buttons, Links & Actions/New

*Make sure Behavior is ‘Execute JavaScript’

 

 

Home Free!

Once you’ve tested that your checkbox gets checked, the world is your oyster.  You can now build declarative automation (i.e. workflows, process builders/flows) by using ‘Activate_Button_Checkbox__c=TRUE’ in your entry criteria.

 

The trick is, to be able to reuse the button, you’ll need to uncheck the checkbox as part of your automation.  (A field update where ‘Activate_Button_Checkbox__c=FALSE’.

 

The benefit of setting up your button this way is that if your process changes, your changes will be made in your declarative automation instead of in JavaScript. 

Share on Facebook
Share on Twitter
Please reload

Please reload

Archive

(303) 953-0078

Fax (866) 618-4062

777 29th Street, Suite 202 Boulder, CO 80303

©2019 BY VISUAL DATA CONSULTING.