How to create S-Control in Salesforce ?

To demonstrate this, lets consider an example of Google Map.
Lets create a S-Control for the Google Map.
Now let’s first create a new S-Control:
  1. Click on “Setup” which is located on the top right corner of the force.com page.
  2. Expand “Develop” item and click on “S-Controls”
  3. Hit “New Custom S-Control”
  4. Provide a Label “Google Map” and a description is you wished to
  5. The Type should be HTML since we want to create a HTML, Google API mash up
  6. Now it is time to enter the code for the S-Control



123451-<html xmlns="http://www.w3.org/1999/xhtml" xmlns:v="urn:schemas-microsoft-com:vml">
2-<head>
3-<meta http-equiv="content-type" content="text/html; charset=utf-8" />
4-<title>Google Maps JavaScript API Example: Advanced Directions</title>
5<link href="/dCSS/Theme2/default/common.css" type="text/css" 
123    media="handheld,print,projection,screen,tty,tv"
6-rel="stylesheet">
7-<link href="/dCSS/Theme2/default/custom.css" type="text/css" 
12345678     media="handheld,print,projection,screen,tty,tv"
8-rel="stylesheet">
9-<script src=" http://maps.google.com/?file=api&amp;v=2.x&amp;key={YOUR KEY}"
10type="text/javascript"></script>
11-<script src="/js/functions.js" type="text/javascript"></script>
12-<script type="text/javascript" src="/soap/ajax/13.0/connection.js"></script>
13-<style type="text/css">
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535414-body {
15-font-family: Verdana, Arial, sans serif;
16-font-size: 11px;
17-margin: 2px;
18-}
19-table.directions th {
20-background-color:#EEEEEE;
21-}
22-img {
23-color: #000000;
24-}
25-</style>
26-<script type="text/javascript">
27-var map;
28-var gdir;
29-var geocoder = null;
30-var addressMarker;
31-var dirFrom = '{!$Request.from}';
32-var dirTo = '{!$Request.to}';
33-var mapLocale = ""
34-var SControlID = '{!$Request.lid}';
35-var SFrameIC = '{!$Request.ic}';
36-function initValues()
37-{
38-mapLocale = "en_US";
39-setInputFields(dirFrom,dirTo);
40-}
41-function setInputFields(from, to)
42-{
43-window.document.getElementById("fromAddress").value = from;
44-window.document.getElementById("toAddress").value = to;
45-}
46-function initialize()
47-{
48-initValues();
49-if (GBrowserIsCompatible()) {
50-map = new GMap2(document.getElementById("map_canvas"));
51-map.addControl(new GSmallMapControl());
52-map.addControl(new GMapTypeControl());
52-gdir = new GDirections(map, document.getElementById("directions"));
53-GEvent.addListener(gdir, "load", onGDirectionsLoad);
54-GEvent.addListener(gdir, "error", handleErrors);
55-setDirections(dirFrom, dirTo, mapLocale);
56-}
57-}
58-function setDirections(fromAddress, toAddress, locale) {
59-if ((fromAddress) && (toAddress))
60-gdir.load("from: " + fromAddress + " to: " + toAddress,
61-{ "locale": locale });
62-}
63-function handleErrors()
64-{
65-if (gdir.getStatus().code == G_GEO_UNKNOWN_ADDRESS)
66-alert("No corresponding geographic location could be found for one of the specified
1   addresses. This may be due to the fact that the address is relatively new, or it may be 
123   incorrect.nError code: " + gdir.getStatus().code);
67-else if (gdir.getStatus().code == G_GEO_SERVER_ERROR)
68-alert("A geocoding or directions request could not be successfully processed, yet the 
123   exact reason for the failure is not known.n Error code: " + gdir.getStatus().code);
69-else if (gdir.getStatus().code == G_GEO_MISSING_QUERY)
70-alert("The HTTP q parameter was either missing or had no value. For geocoder requests, 
1   this means that an empty address was specified as input. For directions requests, this means 
123   that no query was specified in the input.n Error code: " + gdir.getStatus().code);

71-// else if (gdir.getStatus().code == G_UNAVAILABLE_ADDRESS) <--- Doc bug... this is either 
12   not defined, or Doc is wrong
72-// alert("The geocode for the given address or the route for the given directions query cannot
123   be returned due to legal or contractual reasons.n Error code: " + gdir.getStatus().code);
73-else if (gdir.getStatus().code == G_GEO_BAD_KEY)
74-alert("The given key is either invalid or does not match the domain for which it was given. n Error 
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616275-code: " + gdir.getStatus().code);
76-else if (gdir.getStatus().code == G_GEO_BAD_REQUEST)
77-alert("A directions request could not be successfully parsed.n Error code: " + gdir.getStatus().code);
78-else alert("An unknown error occurred.");
79-}
80-function onGDirectionsLoad(){
81-// Use this function to access information about the latest load()
82-// results.
83-// e.g.
84-// document.getElementById("getStatus").innerHTML = gdir.getStatus().code;
85-// and yada yada yada...
86-}
87-</script>
88-</head>
89-<body onload="initialize()" onunload="GUnload()">
90-<div style="background-color: #CCCCCC">
91-<form action="#" onsubmit="setDirections(this.from.value, this.to.value, this.locale.value); return false">
92-<table>
93-<tr>
94-<th align="right">
95-From:&nbsp;</th>
96-<td>
97-<input type="text" size="25" id="fromAddress" name="from" value="" /></td>
98-<th align="right">
99-&nbsp;&nbsp;To:&nbsp;</th>
100-<td align="right">
101-<input type="text" size="25" id="toAddress" name="to" value="" /></td>
102-<th align="right">
103-Language:&nbsp;</th>
104-<th align="right">
105-<select id="locale" name="locale">
106-<option value="en" selected="selected">English</option>
107<option value="fr">French</option>
108-<option value="de">German</option>
109-<option value="ja">Japanese</option>
110-<option value="es">Spanish</option>
111-</select>
112-</th>
113-<td>
114-<input name="submit" type="submit" value="Get Directions!" /></td>
115-</tr>
116-</table>
117-</form>
118-</div>
119-<div style="border-width: 1px; border-color: #000000; border-style: solid;">
120-<div style="overflow: auto; width: 99.5%; height: 380px">
121-<table class="directions" style="width: 100%; height: 100%">
122-<tr>
123-<td valign="top" style="width: 275px;">
124-<div id="directions" style="width: 275px; background-color: #ffffff;">
125-</div>
126-</td>
127-<td valign="top">
128-<div id="map_canvas" style="width: 100%; height: 375px; background-color: #ffffff;">
129-</div>
130</td>
131-</tr>
132-</table>
133-</div>
134-</div>
135-</body>
136</html>




For  Hosting S-Control in Visualforce Page for google map click here




Post a Comment

MKRdezign

Contact Form

Name

Email *

Message *

Powered by Blogger.
Javascript DisablePlease Enable Javascript To See All Widget