+ Start a Discussion

Wanted: an example of an Scontrol using JavaScript and the COM Toolkit

I want to build an SControl out of JavaScript, using the COM Toolkit to implement it.

I'm struggling ... probably not too surprisingly ... learning SControl's functions, expanding my novice level knowledge of JavaScript, searching for how to interface JavaScript to the Toolkit DLL, and working without documentation of the COM toolkit.

Thus ... if anyone has one or more portions of this working, I'd be forever grateful for a helping hand.

My goal, for what it is worth, seems simple: from an opportunity, run script which performs inter-field data integrity checks, informs the user of any problems, and updates a status flag in the opportunity.




Hi Scot,

Attached is a simple sample.

Create a new sforce Control and paste the entire html into the text area.  Then add a web link like normal.




Thanks, Dave.
This looks perfect -- it will give me a huge headstart.

Lizzy BeeLizzy Bee

When I click on the buttons, I'm getting errors saying that the ActiveXObject can't be created.  Any ideas?






I have gotten it working with IE (though it fails with Netscape).

These may be dumb questions, but ...

      > You are using IE?
I have gotten this working with IE, but it fails -- without messages -- in Netscape. The trouble there is, in fact, getting the ActiveX object loaded.

      > Have you installed the Office Edition?
The office edition install downloads and registers the COM Tookit's DLL, making it available. When the install is done, you've got a file, by default, in:
   \Program Files\salesforce.com\OfficeToolkit\1.0\SF_MSApi.dll

The install not only downloads the DLL file, but also registers it for use. If I were in your shoes, and did not get any other advice from the sf.com folks, I'd try de-installing and re-installing the Office Edition.



If you run this against a production salesforce.com account, even as a test, you'll want to change the sample query in the code!  As written, it returns a list of all the contacts in your system (in my case, far too many records).

A good test is to add a where clause to the TWO SOQL queries, changing:

"Select FirstName, LastName, Id from Contact" to
"Select FirstName, LastName, Id from Contact where AccountID = '{!Account_ID}'"

Then, put this into a link on the Account page, and it will limit the list of contacts to those for the account.


Lizzy BeeLizzy Bee


Thanks so much!  I reinstalled the Office Edition and it worked perfectly.


Lizzy BeeLizzy Bee
You also mentioned that you wanted to update a field in the opportunity.  Do you know how you would do that?


Yes, and no.

That is, I can't quote it off the top of my head, but I know that I can figure it out. Since there is no documentation of the Toolkit, you need to do a bit of sleuthing to make progress.

The sources I use are:

    1)  The API documentation, which gives the underlying functionality.

    2)  The object browser located in the VBA editor in Excel. This gives the methods and properties exposed by the toolkit. (Open object browser, pick the library SForceOfficeToolkitLib, and browse). It can't tell you how to use them, but it provides a starting point.

    3)  The sample Excel file provided in an earlier comment. I'm not sure where it is, so I've attached another copy to this note. Unfortunately for updating, this sample, like the control script in this thread, uses queries only.

    4)  The code in the Excel Add-in. This is much more complex, but has examples in it of calls to update, create and delete instances. It takes a while to find the relevant code, but it's much easier than guessing.

When I have a sample of an update, I'll post it ....


there are several samples of its usage in Excel. A quite complex one is the Excel Plug-in. A much simpler one is



Correction ... and apologies ...

The sample Excel file does contain samples of updating, inserting, and deleting using the Toolkit methods. It builds a menu bar with choices to do each of these things, and the subroutines RunUpdate, RunCreate, and RunDelete show how to access them.