Decoding Salesforce

Decoding Salesforce

The hows and whys of Salesforce.com

Posts Tagged ‘Script’

sfdc-web2anything

Long time no update. I know, I know..

We’ve launched an opensource project to help you generate web forms for the live collection/insertion of data in any standard or custom Salesforce.com object.

sfdc-web2anything

Although Salesforce.com Sites will soon be in Developer Preview, we thought that some Salesforce.com customers could find it useful.

Check the project website for details at Google Code: http://code.google.com/p/sfdc-web2anything/

Tabbed Account page using Visualforce

Ok, so, I’ve been poking around at Visualforce a little in my spare time and I came across this tutorial on how to create a tabbed Account page on the Salesforce Developer site.

Check it out! Tabbed browsing within records in salesforce, this should help tidy up some of those annoyingly long Page Layouts.

I’ve implemented this in my Developer Org and it Looks great, I can’t wait until Visualforce is released to Production.

The World Of Apex

Hi Everyone! Sorry for the long absence from posting.

Where have I been I hear you ask, as the title of the post suggests, I’ve been lost in the “The World of Apex”, as I like to call it.

What is Apex? Apex is salesforce.com’s on demand programming language, it’s similar to Java in its syntax but differs in some important ways; you can get all the info on the force.com developer site.

For an administrator like me Apex is one of the most useful technologies that Salesforce have produced, it allows so much more flexibility when building customization onto your existing applications and building new custom applications.

Before I go into much more detail I want to get one thing clear, I am by no means a developer, I’ve done some small amounts of programming here and there, but nothing substantial, I don’t even hold a college degree, so if I can program Apex so can you!

When I started looking into Apex I was amazed at how powerful it was but found out very quickly how much hassle it can also cause. Salesforce have built what they call governor limits into Apex, which is basically a set of in built limits which you need to work within when developing; you can find more information about it here. The reason for this is that instead of running on your machine, Apex runs completely on the salesforce.com servers and they simply can’t afford that someone would write a program that could hog all the resources on their servers and cause the whole system to crumble.

Over the next few posts (I say posts because I really don’t know how often I’m going to get posting) I’m going to go through some basic concepts of Apex and provide examples of Apex triggers and classes I’ve written.

If you’ve visited the link above to the developer site you’ll also have seen information on that page regarding Visualforce. Visualforce is a HTML like markup language that allows you to restructure and build custom pages and User Interfaces for your salesforce.com implementation, currently its still in a developer preview and isn’t available to your live systems so I won’t be delving into that one just yet.

Well that’s the introductions out of the way, next post: “Getting Started”..

Inline Google Maps

Many have asked me how to integrate Google Maps in a Salesforce.com page to pinpoint a specific address on the map. The example we’re going to see today is how to add an inline map to pinpoint an Account billing address.

The finished product

Here’s a screenshot of what we are going to get:
Inline Google Maps

Let’s get started

Right so, let’s see what we need:

  1. First off you need a Google Map API Key you can obtain for free from here; it’s necessary to embed Google Maps in your own web pages. When requested to insert your website URL, enter the name of the instance you’re on, complete with https:// (e.g.: https://emea.salesforce.com/ )
  2. Then, within Salesforce.com, navigate to Setup > Customize > Develop > S-Controls > New S-Control; specify a Label (e.g.: “Inline GMaps”), set the Type to be HTML, in the HTML Body section paste the following code (don’t forget to substitute YOUR-GOOGLE-MAPS-API-KEY-HERE with the Google Maps API Key you created in step #1), then Save.
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml" xmlns:v="urn:schemas-microsoft-com:vml">
    <head>
    <meta http-equiv="content-type" content="text/html; charset=UTF-8"/>
    <script src="http://maps.google.com/maps?file=api&amp;v=2.x&amp;key=YOUR-GOOGLE-MAPS-API-KEY-HERE" type="text/javascript"></script>
    <script type="text/javascript">
    var map = null;
    var geocoder = null;
    var address = "{!Account.BillingStreet}, {!Account.BillingPostalCode} {!Account.BillingCity}, {!Account.BillingState}, {!Account.BillingCountry}";
    function initialize() {
    if (GBrowserIsCompatible()) {
      map = new GMap2(document.getElementById("map_canvas"));
      map.addControl(new GSmallMapControl());
      geocoder = new GClientGeocoder();
      geocoder.getLatLng(
        address,
        function(point) {
          if (!point) {
            document.getElementById("map_canvas").innerHTML = address + " not found";
          } else {
            map.setCenter(point, 13);
            var marker = new GMarker(point);
            map.addOverlay(marker);
            marker.bindInfoWindowHtml("{!Account.Name}");
          }
        }
      );
    }
    }
    </script>
    </head>
    <body onload="initialize()" onunload="GUnload()">
    <div id="map_canvas" style="width:100%;height:300px"></div>
    </body>
    </html>
    
  3. Next, navigate to Setup > Customize > Accounts > Page Layouts and click on Edit next to the correct page layout (you might only have one). Click on Create New Section with Name “Google Maps”, “Single” Columns, leave the two checkboxes checked and click Ok.
    Now, on the right hand side of the screen, from the View dropdown list, select Custom S-Controls; you’ll see the newly created S-Control (e.g.: “Inline GMaps”) and all you need to do is to drag and drop that component into the newly created section.
    Lastly, double-click on the S-Control component now in the section: a popup window will appear. Make sure the Width (in pixels or %) is 100%, set the Height (in pixels) to 300 and untick both the underneath checkboxes.
  4. All done! :) Navigate to one of your Account records and verify the map is displaying correctly!

I’m not going to analyse the S-Control line by line, with a little knowledge of HTML and JavaScript you should be able to modify it to suit your needs, but please let me know if you have any issues.

Play with Custom Links: Part 2

In my last post I explained how to build a simple web custom link; more complex custom links can be used to pass data from your Salesforce records, user information, or company information to another website or application; it can also be used to pass variables from one Salesforce object to another.

Let’s see how to create a custom link to pass fields values from a Salesforce object to another.

Scenario

We give support to different companies and accordingly to what kind of support type a company has, their cases have to be handled differently. We’ve created a custom field for the Account object called Support Type, of type Picklist, containing the variables: “Silver, Gold, Platinum“; we created the same Support Type field for the Case object, same type, same picklist values. We now need to create a custom link in the Account object so when we click on it, we get redirected to a Case page where Account Name and Support Type are filled accordingly to the values present on the Account record.

How to proceed – a step by step guide

First of all we need to find out where in the Case record page our values are going to be “written” to; we basically need to find out the ID of the HTML INPUT fields: Support Type and Account Name.

UPDATE: In order to find a field’s ID please check this post :D

Let’s now move to: Setup > App Setup > Customize > Accounts > Buttons and Links, click on the New button, specify a Label (eg: “New Case”), the Name will be filled in automatically, select the Display Type, the Behavior, make sure the Content Source is URL.

We’re now about to start writing our custom link; the last thing we need is the Object’s code for the Case object: 500 (where did I get this from? Did you read all the old posts? ;) ).

  1. Our custom link will start with: /500/e? which points to the edit page of a new case record.
  2. Now we can pass the variables: cas4, the ID of the Account Name INPUT field in the Case object, will have to contain the actual account name, so we can write cas4= and select Account Name from the Insert Field drop-down list. This will automatically insert {!Account.Name}.

    So far we have:

    /500/e?cas4={!Account.Name}
  3. We have to add an & (ampersand) within the variables.
  4. 00N20000000thpg, the ID of the Support Type INPUT field in the Case object, will need to contain the value of the selected account’s Support Type field, so we can write 00N20000000thpg= and select Support Type from the Insert Field drop-down list. This will automatically insert {!Account.SupportType__c} in the textarea. So far we have:
    /500/e?cas4={!Account.Name}&00N20000000thpg={!Account.SupportType__c}
  5. Doesn’t it look good? :) And it’s almost complete. We can add a retURL to point the user back to the account’s page when the case is saved. Just add retURL=/{!Account.Id} and we’re done! All together!:
    /500/e?retURL=/{!Account.Id}&cas4={!Account.Name}&00N20000000thpg={!Account.SupportType__c}

This should give you an idea of how a custom link works. I hope I’ve been clear enough, if you have any question, just add a comment. :)

Page 1 of 212»