Monday, 27 September 2010

S-Controls

As I mentioned in my previous entry, Visualforce is the new standard technology that allows you to create custom user interfaces for your force.com applications. I would love to be able to begin teaching you how to build your own applications using Visualforce, but before doing so it is imperative that we re-examine S-controls.

Since S-Controls have been denigrated we can only edit existing ones and install the ones that subsist in legacy managed packages.  However this remnant of older Salesforce programming is still necessary knowledge for the aspiring developer.

S-Controls allow the developer to create custom content. This is hosted by the SFDC system but is actually executed by specific end client applications. It is common knowledge that these S-Controls will usually have a mix of HTML and JavaScript. You can use the Salesforce AJAX Toolkit to update the SFDC data that is JavaScript. The HTML controls and displays the data.

The following is a sample S-Control code using the AJAX Toolkit. It will display a “SF Giants Rule” greeting for the end user:

<html>
<head>
  <script type="text/javascript" src="/js/functions.js"></script>
  <script src="/soap/ajax/8.0/connection.js"></script>
  <script>
    function setupPage() {
      // Use the API connection, named sforce by default, to get
      // the full name of the active user
      var user = sforce.connection.getUserInfo().userFullName;
      // Display "Hello World" plus the full user name by replacing
      // the div defined below
      document.getElementById('userNameArea').innerHTML =
      'SF Giants Rule, '+user;
    }
  </script>
</head>

<body onload=setupPage()>
  <div id=userNameArea>
  </div>
</body>
</html>

Once this new S-Control is created with this code, you can add it to the page layout of an existing object or connect it to its own custom tab. After either one these are loaded, you will see the text “SF Giants Rule” with the user name. This text will be displayed in the S-Control area that they developer has defined.

I am well aware that this very simple description on the use of S-Controls, but it will give you insight on why many developers prefer Visualforce (especially myself) in the next post. 

No comments:

Post a Comment