Decoding Salesforce

Decoding Salesforce

The hows and whys of Salesforce.com

Author Archive

Apex Code: What you need to get started…

Following on from my previous post.

Below is what you’ll need to get started developing with Apex.

  1. A salesforce.com Developer Edition Account: sign up from the developer site developer.force.com
  2. Apex Documents: available from the Developer Wiki, Apex and Visualforce Section.
  3. The Force.com IDE: just follow the steps on the site to set it up.
  4. A basic understanding of Object Oriented Programming. Personally I’ve done some C and Visual Basic programming in college but not much since. Its a benefit to understand collections and Loop structures, but not essential. If you don’t have a programming background don’t be too worried.
  5. Willingness to Learn and some Spare time: I put this in here for one simple reason, it takes time to learn this stuff and get to grips with it. Personally I’ve been playing around with Apex for a few months now, which has left me no time for this blog.

Next Section: Setting up your first Apex Project…

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”..

Breaking Formula Compile Size Limit

UPDATE: As you can see we received a comment to this post from Eric Bezar from Salesforce.com; they said that this is an exploitation of a bug in the application and it can not be guaranteed to work in the long term. In other words don’t use this method. Daniel gave a very good workaround if you run into this problem: you can use a workflow field update to update the value in a field with a formula value then use that field in your formula. This gets around the compile size limit and it’s something Salesforce.com can support. Thanks Eric for the info :)

Everyone who creates formulas in salesforce knows how annoying their 4,000 character compile size limit is.

Well, good news! :) There is a way around it.

Its a simple enough thing to do and according to their support its not something that is going to change in the future but I’m not going to guarantee you they won’t. First of all you need to be aware of the current work around to get past their 1,300 character limit for formulas.

The basic process is to reference one formula off another. For example, if you’re using a case statement and you run out of room you create another another formula and continue your case statement, then in the first formula you put the merge field for the second formula in the else_result position.

E.g.:
Formula 1:
Case(expression,value1,result1,value2,result2,…,value100,result100,formula2)

Formula 2:
Case(expression,value101,result101,value102,result102,else_result)

In my case I have a picklist field which lists all of the countries in which we do installs and when a sales rep closes a sale they need to fill in the country where the install will be.

Once that is done I wanted to do two things:

  1. Create a formula to show the region for the installation.
  2. Create another formula based on the region and the amount to calculate who the lead on the install will be.

I built the following formula to calculate the region. Its called installation_region:

CASE( Installation_Country__c ,"Albania","EMEA",
"Algeria","EMEA",
"Andorra","EMEA",
"Angola","EMEA",
"ANtigua and Barbuda","US",
"Argentina","US",
"Australia","APAC",
"Austria","EMEA",
"Azerbarjan","APAC",
"Bahamas","US",
"Bahrain","APAC",
"Bangladesh","APAC",
"Barbados","US",
"Belgium","EMEA",
"Brazil","US",
"Bulgaria","EMEA",
"Cambodia","APAC",
"Canada","US",
"Chile","US",
"China","APAC",
"Denmark","EMEA",
"Egypt","EMEA",
"Estonia","EMEA",
"Finland","EMEA",
"France","EMEA",
"Germany","EMEA",
"Greece","EMEA",
"Hungary","EMEA",
"Iceland","EMEA",
"Ireland","EMEA",
"Israel","EMEA",
"Italy","EMEA",
"Japan","APAC",
"Latvia","EMEA",
"Luxembourg","EMEA",
"Macedonia","EMEA",
"Malta","EMEA",
"Mexico","US",
"Monaco","EMEA",
"Mozambique","EMEA",
"Nepal","APAC",
"Netherlands","EMEA",
"New Zealand","APAC",
"Norway","EMEA",
"Poland","EMEA",
"Portugal","EMEA",
"Romania","EMEA",
"Russia","EMEA",
"Singapore","APAC",
"Slovakia","EMEA",
"South Africa","EMEA",
"Spain","EMEA",
"Sweden","EMEA",
"Switzerland","EMEA",
"Thailand","APAC",
"Turkey","EMEA",
"Ukraine","EMEA",
"UAE","APAC",
"UK","EMEA",
"US","US","UPDATE FORMULA")

This compiled to 2,179 characters. Then I built the following formula to calculate the lead and called it installation_lead:

IF(Amount > 100000, CASE( Installation_Region__c , "EMEA","Mark","APAC","Dave","US","James","UPDATE FORMULA") , "Mike")

But this compiled to 6,763 characters so I couldn’t save it.

Then after reading up on something I had a brainwave. The reason the installation_lead wouldn’t save is because it references installation_region which is a very large formula. I copied the original installation_region formula and pasted it into a text editor and I modified the installation_region to be:

CASE( Installation_Region__c ,"Albania", "EMEA", "US", "US", "UPDATE FORMULA" )

This compiled to be 104 Characters long. I saved this simplified version of the formula and tried the second formula again. It then saved and compiled as 538 characters. I saved it and went back and pasted back in my original installation_region formula and it saved without any problem.

Just out of curiosity I checked installation_lead and if I edited it I couldn’t save it because it was over the compile size but on the page layout both work perfectly.

So all you have to do to get around the compile size limit is:

  1. Create a simple version of a formula and save it.
  2. Create a master formula refrenecing the formula created in step one and make sure its as complicated and as long as it needs to be and save it.
  3. Go back and edit the formula created in step one and extend it to contain all of the information you need and save it.

The formula in step 2 may go over the compile size but as it is already saved it won’t stop you using it.

I can’t guarantee you this will work forever but its better then nothing.

Validation Rule formulas: Part 2

Leading on from my last post I’m going to go into further detail of building your validation rules.

Step 1: Understanding formulas

First off you need to understand the basics of building formulas in salesforce. To do this I’d start looking at all the help and training information on formulas which salesforce already provide, this can easily be found by going to the Help & Training Link in salesforce and searching for the term Building Formulas. There is a wealth of information available here which can be extremely useful to the new salesforce administrator.

Also find below two useful links for getting used to building formula fields.

Once you’re comfortable building normal formulas the next step is to have a look at the resources below. These useful resources are all about validation rules specifically.

At this point you should have the basics.

Once you have the basics in building these things you need to try it out. I don’t believe it’s a good idea to try things out in your production salesforce account as some of the fields you’re adding may confuse your users.

I suggest either getting a sandbox; you can get one by contacting your salesforce support rep. They’re an extra charge but I believe they’re worth it. As you can copy all your customization to it and then work with the fields you have in your production instance. Check it out here.

If you don’t have the money for this you can get a free developer account by joining the developer network.

Well that’s it for today but this should get you on the road to being a formula master :)

Page 1 of 212»