Loading
Salesforce now sends email only from verified domains. Read More
Enhance Salesforce with Code
Table of Contents
Select Filters

          No results
          No results
          Here are some search tips

          Check the spelling of your keywords.
          Use more general search terms.
          Select fewer filters to broaden your search.

          Search all of Salesforce Help
          Useful S-Controls

          Useful S-Controls

          Use these samples to get started using s-controls.

          Required Editions

          Important
          Important Where possible, we changed noninclusive terms to align with our company value of Equality. We maintained certain terms to avoid any effect on customer implementations.
          Available in: Salesforce Classic
          Available in: Contact Manager, Group, Professional, Enterprise, Performance, Unlimited, and Developer Editions
          Available in: Salesforce Classic

          Custom buttons and links are available in: All Editions

          S-controls are available in: Contact Manager, Group, Professional, Enterprise, Performance, Unlimited, and Developer Editions

          Overriding standard buttons and tab home pages is available in: Enterprise, Performance, Unlimited, and Developer Editions

          Important
          Important Visualforce pages supersede s-controls. Organizations that haven’t previously used s-controls can’t create them. Existing s-controls are unaffected, and can still be edited.

          S-Controls for Detail Pages

          Use the Yahoo Map API and the billing address merge fields to display a map for an account.

          Yahoo Map

          Use the Yahoo Map API and the billing address merge fields to display a map for an account. Use the following code in an HTML s-control and add it to your account detail page layout:

          <html>
          <head>
          <script type="text/javascript"
          src="http://api.maps.yahoo.com/ajaxymap?v=3.0&appid=YahooDemo">
          </script>
          <style type="text/css">
          #mapContainer {
          height: 200px;
          width: 100%;
          }
          </style>
          </head>
          <body>
          <div id="mapContainer"></div>
          <script type="text/javascript">
          // Create a map object
          var map = new YMap(document.getElementById('mapContainer'));
          // Display the map centered on given address
          map.drawZoomAndCenter("{!Account.BillingStreet}, \
           {!Account.BillingCity},\
           {!Account.BillingState},\
           {!Account.BillingPostalCode}", 3);
          // Set marker at that address
          map.addMarker("{!Account.BillingStreet}, \
           {!Account.BillingCity},\
           {!Account.BillingState},\
           {!Account.BillingPostalCode}", 3);
          </script>
          </body>
          </html>

          S-Controls that Override Standard Buttons and Tab Home Pages

          You can have your own code that you prefer to use for adding products to opportunities instead of the standard page.

          Add Product Override

          Use the following s-control sample to pass data values using merge fields from a record detail page into a custom s-control that overrides the Add Product button on the Products related list of an opportunity. This type of override illustrates how related list buttons can contain merge fields from the master object as well as the detail. For example, this code contains opportunity merge fields, which is on the master side of a master-detail relationship with opportunity products.

          <html>
          <head>
          <script type="text/javascript"
          src="/soap/ajax/13.0/connection.js">
          </script>
          </head>
          <body>
          <b>Opportunity Info:</b>
          <br>
          Opportunity ID: {!Opportunity.Id}
          <br>
          Opportunity Name: {!Opportunity.Name}
          <br>
          Opportunity Record Type: {!Opportunity.RecordType}
          <br>
          </body>
          </html>

          To implement this functionality, create an HTML s-control with the previous content and inserting your code in the space provided. Then, override the add product action from the opportunity products object using the s-control. This example assumes you have record types on opportunities.

          Note
          Note This example does not include the code to add products. The content in the body section simply illustrates how to use opportunity merge fields from the opportunity products related list. Replace the body section with your code.

          Conditional Override for Editing Leads

          You can override a standard action conditionally, redirecting to a standard action or custom s-control depending on certain conditions. For example, you want to use a separate s-control to edit leads when they have been open longer than 30 days. Using the following example, create an s-control to evaluate if a lead has been open longer than 30 days and, if so, run your custom s-control to edit leads. Otherwise, use the standard lead edit action.

          <script type="text/javascript">
          
          //determine if the lead has been open longer than 30 days
          if ({!IF(ISPICKVAL( Lead.Status , "Open"), ROUND(NOW()- Lead.CreatedDate , 0), 0)} > 30)
          {
          //more than 30 days - display a custom scontrol page
          window.location.href="{!URLFOR($SControl.EditLeadsOpenLongerThan30)}";
          }
          else
          {
          //30 days or less - display the standard edit page
          window.parent.location.href="{!URLFOR($Action.Lead.Edit, Lead.Id, [retURL=URLFOR($Action.Lead.View, Lead.Id)], true)}";
          }
          
          </script>

          To implement this in your organization, create the s-control that you want to use to edit leads that have been open longer than 30 days. Name this s-control EditLeadsOpenLongerThan30. Next, create an s-control using the previous example code to determine if a lead has been open longer than 30 days, and, if so, override the edit action on leads using the EditLeadsOpenLongerThan30 s-control.

          Note the differences between the first and second if statements in the previous example code. The first one is a JavaScript if statement that evaluates on the browser. The second is the Salesforce IF function that evaluates on the server and returns a single value—the number of days the lead has been open, or zero if the lead is not open.

          Tip
          Tip Use the URLFOR function in this example to build Salesforce URLs rather than specifying individual URLs to ensure they are supported across releases.

          To display a standard Salesforce page without invoking the override, set the no override argument in the URLFOR function to “true.”

          Also, use the retURL parameter in your URLFOR function to return the user to the detail page after saving.

          Edit Contact Override

          You can have your own code that you prefer to use for editing contacts. Use this s-control sample to pass data values using merge fields from a record detail page into a custom s-control that overrides a standard detail page button.

          <html>
          <head>
          <script type="text/javascript" src="/soap/ajax/13.0/connection.js">
          </script>
          </head>
          <body>
          <b>Contact Info:</b>
          <br>
          Contact ID: {!Contact.Id}
          <br>
          Contact Name: {!Contact.FirstName} {!Contact.LastName}
          <br>
          </body>
          </html>
          

          To implement this functionality, create an HTML s-control with the previous content inserting your code in the body section. Then, override the edit contact action using the s-control. This overrides the edit contact action everywhere it is available: the Edit button on a contact detail page, the Edit link on list views, and the Edit link on any related lists.

          Note
          Note This example does not include the code to edit contacts. The code within the body section only illustrates how to use contact merge fields to display information about the contact. Replace the body section with your code.

          Interrupt Override for New Accounts

          Overriding standard buttons makes them unavailable in your entire Salesforce organization. However, you can override a standard action and redirect to that action from your s-control without getting into an infinite loop. For example, you can override the New button on accounts, perform your own custom process, and resume with the standard new account action without getting into an infinite loop. To do this, use the no override argument in the URLFOR function.

          <script type="text/javascript">
          
          alert("Hi, I am demonstrating how to interrupt New Account with an override.  Click OK to continue.");
          
          window.parent.location.href="{! URLFOR($Action.Account.New, null, null, true)}";
          
          </script>
          

          To implement this s-control, create an HTML s-control with the previous content. Then, override the new account action using the s-control.

          Note
          Note The new action does not require an ID, which is why the second argument in the URLFOR function is set to null. This example does not require any inputs, which is why the third argument in the URLFOR function is set to null. The fourth argument in the URLFOR function is set to true to ignore the override, avoiding an infinite loop.

          Conditional Accounts Tab Home Page Override

          You can override a tab home page conditionally, redirecting the original tab home page to an s-control depending on certain conditions. For example, you want to display an s-control, instead of the standard Accounts tab home page, to users with a specific profile. Using the following sample code, create an s-control to display job applicant information to users with the Recruiter profile when they click the Accounts tab; for all other users, display the standard Accounts tab home page.

          To implement this, first create an s-control called “ApplicantHomePage” that contains the content to display to recruiters. Next create an s-control of type HTML using the following code to implement the conditional override logic:

          <script type="text/javascript">
          //determine the user profile name
          var recruiter = {!IF($Profile.Name = "Recruiter", true, false)};
          
          //when the profile is recruiter - display a custom s-control page
          if (recruiter) {
              window.parent.location.href="{! urlFor($SControl.ApplicantHomePage)}";
          } else {
          //when the profile is not recruiter - display the standard Accounts tab page
              window.parent.location.href="{! urlFor( $Action.Account.Tab , $ObjectType.Account,null,true)}";
          }
          </script>

          Finally, override the Accounts tab to use the HTML s-control shown here. This example assumes that a profile named “Recruiter” exists in your organization.

          Note
          Note $Profile merge fields are only available in Enterprise, Unlimited, Performance, and Developer Editions.

          S-Controls that Include Snippets

          Include snippets in your custom s-controls to reuse common code.

          Including Snippets

          The following example references a snippet that provides a header for a page that displays in a web tab. The page has the title “My Title.” Use the $Control global variable to reference a snippet. To implement this, create two snippets called “Resize_Iframe_head” and “Resize_Iframe_onload” and create an HTML s-control called “Resize_Iframe_sample” that includes this code.

          <html>
              <body>
                  {!INCLUDE(
                      $SControl.Header_Snippet, 
                      [title = "My Title", theme = "modern"]
                   )}
              </body>
          </html>
           
          Loading
          Salesforce Help | Article