# Timeout

To the few precious readers that I manage to attract to my blog, I want to apologize for missing a couple of weeks. There was a user group meeting, and then a trailhead workshop, (locusts, a terrible flood, I wasn’t my fault I swear to Gooooooooooood!!!) that I had to prep for so I missed a couple entries. It’s all for the good though because interest in the Logic Through Formulas has sort of stalled out and to be honest, I’m lacking ideas for content. Therefore, I’m taking a timeout on that series but it will still be here for any admins that may want to see a “formula in code” if they think it will help them learn something more. So if you’re out there, don’t hesitate to send me something :)

So in case you missed it, our Wisconsin based “Women in Tech” group sponsored a Trailhead Workshop in Lake Mills, WI over the weekend and was a great success. (Though we ARE still waiting for a number the feedback surveys). We plan to do more, so follow myself or either of these two fine folks on Twitter: Jenny Bennett & Kelly Leslie, in order to get the latest news on the next workshop. We also had the great pleasure to welcome Chris Duarte to the midwest. She made it through her weekend without freezing, so that’s a plus ;)

For a recap: see ChattyAdmin’s blog (ignore the googy-ass face I was making…we were all supposed to be, but I don’t think anyone else knew, but I DISTINCTLY heard someone say “make a funny face”)

# Apex Logic Through Formulas: Part 3

I’ve had to reach into my own bag of formulas to find an example for this week’s entry. Last week I was focused on our local user group so we didn’t have an entry, this week I’d like to make up for that a little bit. This week’s formula is a bit more involved but nothing crazy:

Let’s walk through what the formula does:
First we have an AND function wrapped around everything. If we think of the AND function as this box that we just put things into and shake up and look inside our AND box will contain a value of either TRUE or FALSE. If everything we threw inside our AND box is TRUE, then our overall value should be TRUE. If even one item in our AND box is FALSE, the whole thing is FALSE. The trick here is that our AND box contains another BOX that can have its own items inside. This inner box is an OR box and in this case only one of the items inside needs to be TRUE in order for the whole BOX to be TRUE.

So the first item we put in our AND box is checking a Boolean field on our object. This is a checkbox that is basically telling us that this “item” is external. (Let’s ignore the business case for now as its irrelevant, just know that this is a checkbox that will either be check or unchecked. Since a Boolean value is by default either TRUE or FALSE we don’t need to do any sort of comparisons, here. However we did wrap this in a NOT function. So, if our External Item checkbox is indeed checked, (therefore TRUE) our NOT box is reading NOT(TRUE). So basically if our checkbox is checked, this would return FALSE thereby making our entire AND box false. Clear as mud? We’ll try to clear that up when we have an actual example, but for now lets check the next part.

Lines 3 through 7 contain our OR box. We are checking to see if our Opportunity is either in a stage of VALUE1, VALUE2, or VALUE3. (The stages have been changed to something generic as this is an actual formula in an org and I’m not comfortable giving away too much information). So if our Opportunity is set to any of those three stages, our entire OR box will be TRUE. Incidentally if we only had four stages, this OR box could have been removed and we simply could have said inside our AND box: “NOT(ISPICKVAL(StageName, ‘VALUE4’))” meaning if it isn’t VALUE4 than it must be one of the other values, but I digress.

Lastly we are checking a multi-picklist field (ssshhhh don’t tell @SteveMoForce) to see if one of the selected values is ‘APPLICATION’ and if so, then that part will also be TRUE.

Lets walk through an example before we get into code. Lets say we have the following Opportunity information:

```External Item: unchecked
StageName: VALUE2
Item Key: SERVICE and APPLICATION are selected
```

This formula would return TRUE on line 2: NOT(External_Item__c) which is saying NOT(TRUE). If something isn’t TRUE than it must be FALSE. So we are checking to see if External_Item__c is FALSE (unchecked) which it is indeed unchecked, so the result of our NOT box is TRUE, since External Item is not TRUE (checked). (I know its still mud…but you’ll get it).

For our OR box, we are NOT in StageName ‘VALUE1’ but we are in StageName ‘VALUE2’ — so since one of our items in our OR box is true, the whole OR box is TRUE.

Lastly, our Item Key indeed contains the text ‘APPLICATION’ so that too is TRUE. So basically our big AND box that wraps this whole thing contains:

```AND(
TRUE,
TRUE,
TRUE
)
```

So everything in our AND box is TRUE and therefore our whole box is TRUE and this rule would fire. Its reminiscent of “solving for X” using substitution back in our Algebra days, (and you thought you’d never USE that stuff).

Now let’s code this puppy. Again let’s assume that I’ve done the proper querying of my Opportunity and included the fields that I am interested in. As we did back in lesson 1, we are going with a very verbose solution. This could be written in so many different ways and the idea here is to help you simply tie the logic together. We’ll refactor it, but lets start with using perhaps some nested IF statements (again, this code won’t compile on it own):

Line 1:
This is just our function declaration. Let’s not worry too much here at the moment as the logic is within the braces.

Line2: We are checking to see if the External Item is NOT True (unchecked). This matches our formula’s use of the NOT() function. We could have also written it like this:

```if(myOpportunity.External_Item__c == False) {...}
```

…but that wouldn’t have really matched what our formula was saying. It would have been equal, but not “equivalent” ;)

Line 3:
Using our Opportunity example from above, that would pass and we would fall into our next IF statement on line 3. Here we are checking the Opportunity’s StageName to see if its either ‘VALUE1’, ‘VALUE2’, or ‘VALUE3’. The || symbol in our if statement means “OR” and follows the same rules as the OR box in our formulas. If any of those comparisons are True, then the whole thing passes through to the next line.

Line 4:
Here we are checking to see if our multi-picklist field as APPLICATION for one of its selected values. In Apex, you can use the “contains” function to look into some text to see if a given sequence of letters or numbers are present. Also, a multi-picklist field’s selected values in apex appear as one long string with each selected item separated by a semi colon. So our example would have: ‘SERVICE;APPLICATION’ as the value for that field. PLEASE NOTE: this code as written could wind up in a bug because if for some reason your multi-picklist had both ‘APPLICATION’ and ‘APPLICATION LICENSE’ as viable selections, and someone chose the latter, our code on line 4 would still find the word “APPLICATION” in our selection even though it was part of the “APPLICATION LICENSE” selection. So there is a better way to do that by splitting up the selections into a list and looking for the value that way, but that lies beyond the scope and I don’t want to dive too deeply too soon.

Upon passing line 4 successfully, we return a value of True in our function and we are done. If at any point we don’t pass the if statements, we fall out and wind up on line 9 where we return false.

As stated there are many other ways to write this:

or

but my point is to get you to focus on the similarities of the logic between Apex and Formulas. We can worry about writing more concise code once you get more comfortable with the concepts. Your homework? Yes there is homework. Given the following Opportunity, will it pass our tests or fail them? If it fails, where will it fail?

```External Item: checked
StageName: VALUE3
Item Key: 'SERVICE' and 'APPLICATION' are selected
```

or

```External Item: unchecked
StageName: VALUE4
Item Key: 'SERVICE'
```

I hope this helps you along your path. As always, I am open to suggestion and send me those formulas!

:wq!

# Apex Logic Through Formulas: Part 2

Last week we dove right in with a formula from SteveMo. This week, I want to take a small step back and rather than just transform a formula into Apex, I’d like to talk on a more general level. Often times our formulas are checking for equality between two fields, or one field and some expected value. There are numerous ways to do this in formulas, but I wanted to show you some ways that you can check for equality in Apex as well.

Lets start off with with something simple, like checking if the value of a picklist is equal to some known value. In a formula one would have:

```ISPICKVAL(MyField__c, 'Some Value')
```

In apex however, we don’t need the “ISPICKVAL” and we use the double equals to check for equality as such:

```MyObject.MyField__c == 'Some Value'
```

The above is usually put within an if statement or its result assigned to a variable like this:

```if(MyObject.MyField__c == 'Some Value') {
//do geek things here
}
```

–or–

```myBooleanVariable = (MyObject.MyField__c == 'Some Value')
```

Now lets talk about checking for inequality. Normally this is wrapped in a NOT function within a formula like so:

```NOT(ISPICKVAL(MyField__c, 'Some Value'))
```

In apex we check for not equals usually using the not equal operator (!=):

```MyObject.MyField__c != 'Some Value'
```

Again we put this in if statements or assign to variables as shown above. There are also the >,<, and <> operators but these function identically in apex as they do in formulas:

```Some_Value > 0
Some_Value < 0
Some_Value <> 'some other value'
```

For some the ‘<>‘ operator may be new, its another way of checking for inequality and I prefer to use that method in formulas but use the != notation in apex. I’m not sure why I prefer it that way other than that’s just what I’ve been using in other languages since I started programming and that’s a 15 year habit that I don’t see me breaking anytime soon.

I apologize if this week’s lesson feels a bit light, but you can help with that. Send me your formulas! :)

Until next time

:wq!

# Apex Logic Through Formulas: Part 1

Last week I mentioned that I would be starting a new series of sorts. Today will be the first entry in that series. My hope is to bridge the gap between point and click development, and slinging code for those admins/developers that are hesitant to make “the leap of faith” into the world of of development. As mentioned, fellow MVP @SteveMoForce had mentioned that perhaps seeing a formula of sorts (be it from a validation rule, workflow entry criteria, etc) written out to its equivalent in Apex would be of use to begin understanding it.

While writing this stuff likely isn’t going to be useful to you directly, the intent is that since — as an admin — you are already familiar with how formulas work and how to write them that it isn’t as far a stretch to go from the logic of formulas to the logic of slinging code. After all, that is the biggest hurdle when learning to code, the logic. The rest is just syntax, like learning a new language, and for you the admin, more like learning the nuances of a given dialect of a language.

So for our first example, SteveMo was kind enough to donate the following formula that simply looks at four fields, determines if there is a value in any of them and if there is a value in more than one, return true. I’m told this was part of a validation rule the expects that “any” of the fields can be filled out, but only one of them can contain data at any given time:

```IF(ISBLANK(Field_A), 0, 1) +
IF(ISBLANK(Field_B), 0, 1) +
IF(ISBLANK(Field_C), 0, 1) +
IF(ISBLANK(Field_D), 0, 1) > 1
```

What we have in this formula is a few “IF” functions, some math operations, and a comparison. (Comparisons always return true or false, since a Validation rule fires when its criteria is true, we need a comparison at the end of the day). Before jumping into the coding portion, lets ensure we all understand this formula.

IF(ISBLANK(Field_X), 0, 1):
When you use an IF function in a formula, it checks to find out if a given condition is true. Upon finding it is true it returns the next value in the “IF box”, if its false it returns the last value in the IF. So in this case we are checking to see if the value of the given field (Field_A) is blank. If it is indeed blank (condition is true) then the “value” in our IF box is 0, if it is not blank, the value of our IF box is 1.

We Do Math:
We take the results of these IFs and add them together, if they are all blank we get 0 + 0 + 0 + 0 = 0. If only one of the fields is filled out (it doesn’t matter which), we could get 0 + 0 + 1 + 0 = 1. Lastly if more than one field is filled out (again any combination) we could end up with 1 + 0 + 1 + 1 = 3.

Now we compare:
Finally we will look at the result of our math and check to see if it is greater than 1. If it is greater than one, our Validation Rule becomes TRUE and will fire a message. If it equals or is less than one, our Validation Rule is FALSE and all is well.

So let’s write some Apex:
I know your excited, but I want to clear a few things up. Firstly, we have to imagine for now that we have done some other coding to get access to this object’s fields. Following Steve’s example lets say we have a Widget object with the following four fields: Field_A__c, Field_B__c, Field_C__c and Field_D__c. Furthermore, as it is out of scope for this series, lets assume we’ve written the necessary code to allow us to refer these fields as “MyObject.Field_A__c” etc. Secondly, this code will be very verbose. There will likely be more concise/better ways to write this, but we have to walk before we run. Lastly, I may use words like variable or other “coding words” — I will try to explain those as I go, but remember the concept here is to map what you know of formulas to something you are unfamiliar with so that your mind can begin to marry the two together. This is largely an experiment so whether this helps remains to be seen. Stay with me.

Lets look at the code (I put the code in an image for two reasons. First, so that I get nice line numbers with my code and its easier to do a walkthrough. Second, so that if you wanted to play with this, you’d have to type it in manually. I know, I’m a jerk but cutting and pasting is one thing, but I believe it helps you absorb it all if you type it in as you go. That being said, this won’t compile directly in eclipse or sublime — remember that we are assuming I’ve done some other stuff, but perhaps some of the more enthusiastic amongst you might read up on that “other stuff” and I don’t want you mad at me when it doesn’t compile):

Now lemme ‘splain:
Line 1: Don’t get hung-up here. This is how we write a chunk of code that we can refer to later from some other place. Its called a function and we write code that “calls” it, which basically means, do the stuff in between my curly braces ({…}). For now just consider line 1 and line 33 as the walls of the container in which we are holding our apex version of the validation rule. The “black box” of magic so to speak.

Lines 2-4: Here we are telling the compiler (the bit that checks to make sure our code is valid and will run) that we are going to use some variables to hold integer values (whole numbers, not decimals, not text). Variables are placeholders for items we want to refer back to later, or do something with. In our case, we will be putting a value of either 0 or 1 in each of these based on whether or not our fields have a value in them and adding them up later.

Line 5: Here we are telling the compiler about another variable, but instead of holding a number it will hold a Boolean value which simply put, means its going to hold a value of TRUE or FALSE.

Line 7-11:
This might look familiar, its an IF statement quite similar to the IF function used in our formula. There is a certain syntax wrapped around us here so now would be a good time to point that out. An IF statement in Apex has a condition that you are checking for in parenthesis (in this scenario, the code in between the parenthesis is similar to the ISBLANK portions of our Validation Rule criteria), and then some curly braces. The curly braces separate the logic for us a bit. The code in between the first set of curly braces are evaluated when the condition in parenthesis is true. An if statement may also have more sets of curly braces. In our case we have an “else {…}” block. THIS block gets evaluated when our condition is not true (and therefore false, get it?). At some point in the future we can talk about the “else if {…}” block which allows us to check for numerous conditions by stringing them together, until one of the conditions finally winds up true or we run into an else block, or just run out of conditions to check all together.

So continuing with line 7-11, on line 7 we are checking our condition: if(myObject.Field_A__c == null). What is null you ask? Null is essentially “nothing” — so we are checking to see if there is any value there or not. The check for equality in Apex is the double equal sign “==” so this bit is equivalent to our ISBLANK function in our formula. If there is no value in myObject.Field_A__c then our condition is true and line 8 will get evaluated. On line 8 we store a value of 0 in our Integer variable called “a” — if there was indeed a value in myObject.Field_A__c then our condition would be false and therefore our “else {…}” block would get evaluated and the code on line 10 would tell our Integer variable “a” to hold onto the value of 1.

Lines 13-32: We repeat this logic for all four fields either storing 0 or 1 in each of our variables. When we are done we should have four variables that we can then add the values they hold together like we do on line 31. But that line looks just a bit different doesn’t it? Here we are saying “Hey compiler, remember that Boolean variable I told you about? Well take the value of adding a + b + c + d (my picture left out the + d — sorry) and compare that to see if its greater than 1 and store that result in my isGreater variable.” That may be a bit much to grasp, and I get it. Here’s what is happening. We are adding (a + b + c + d) but much like the order of operations from elementary school, we want that math to happen before we compare it to 1. We could have written it like so:

```Integer i = a + b + c + d;
isGreater = i > 1;
```

But we can put this all on one line. Remember whenever we do a comparison, we either get a TRUE or FALSE value and Boolean variables know how to hold on TRUE or FALSE values.

Lastly, we “return” the result of our comparison to whatever called it (again elsewhere in code). Our validation rule doesn’t have the concept of a “return value” per se — it just IS that result. (Essentially, technically it does “return a value” but you as the admin are shielded from all of that).

Now some of you out there are saying, “WOW that’s quite a bit of code when my formula was only 4 lines long!” and you’d be right, but formulas have some built in magic that hide some of that extra “stuff” from you. Also, remember I said there may be better ways of doing things? Not all code would have to be that long. This next snippet — don’t worry if you don’t get it, its only here for an example and to show you that not all code is so drawn out — would do essentially the same thing:

That above snippet has some more advanced things in them like looping over a list of items, etc. Perhaps we will eventually get there with this series. I’m not sure if we will have Part 2 next week — hopefully so, but it depends on an submissions I may get from readers, or perhaps SteveMo has some more gems hiding somewhere. So feel free to send me your ideas and keep this going. Let me know if you have questions or if I can help clarify anything else in this lesson.

:wq!

# New Mini Series Starting Soon

One of my absolute favorite conversations at Dreamforce this year happened during my last night in San Francisco. I was out until the wee hours of the morning with a group of people and happen to be fortunate enough to sit next to SteveMo and Adam Daw. For those of you that don’t know Adam, he’s a distinguished gentleman, and a fantastic Salesforce Developer that appreciates music, dancing, a fine snifter of armagnac, and a good cigar. I don’t think SteveMo needs any introduction, lets just say he’s “Salesforce famous” shall we? :)

Adam and I got to talking with Steve who mentioned to us that he will do whatever he possibly can to avoid having to “go to code” in his org. We wound our way through various analogies, and Steve mentioned that his fear is that in taking that leap of faith, there will be nothing there to catch him in the end. Adam’s answer was brilliant for two reasons:

1. It referenced Indiana Jones and the Last Crusade
2. I believe it to be 100% relevant

He referenced one of the last scenes where Indy finds himself standing at the edge of huge abyss with certain death waiting below but too far a leap to even consider trying. Indy hears his father’s voice in his head: “Only a leap from the lion’s head will he prove his worth.” Clutching his heart and taking a deep breath, he closes his eyes and steps out facing certain death, only to find that he’s landed on a very cleverly camouflaged stone bridge. It was all an optical illusion. He made the leap, and he was okay.

This prompted me to ask Steve: “As an admin who is unsure about taking this leap, what could we as developers say or do to show you it will okay?” Steve’s response wasn’t one asking for encouragement, it was one of education. He said, “What would help me perhaps, would be to see what a formula I’ve written looks like in Apex.” That got me to thinking that perhaps if that would help Steve, it would help others as well. So, hopefully next week, I will begin a mini series: “Beginning Apex Logic Through Formulas.” This won’t be anything you can directly “use” in your org and nor would I ever suggest that a formula be replaced with Apex, it’s merely meant to serve as a stepping stone for admins who want to get started coding. There is quite a bit of logic in formulas and if you can understand that, you’re halfway there already. The only thing left is to make that translation into Apex, which would be a bit like learning another language, not even a full language, maybe just a dialect.

So that being said, when Steve gets time, he will be sending me his first formula, (I’ve asked him to keep it simple — no fair stumping me on the first pass), but I’d like to open this up to other people as well. If you have a formula that you think would help your understanding of Apex by seeing it written out in code, let me know. I will do my best. I’m not even sure this will work all that well since there are some operations in formulas that are sort of “black boxes” of functionality, but lets take a stab at it and perhaps we can all learn something together.

:wq!

# So Long DF15, It Was VERY Personal

Introduction:
I began composing this entry upon returning to my hotel room after the closing of the Benioff/Harris Q & A session. I wanted to capture what was going through my head (and heart) before I lost it. I didn’t get to finish the whole thing as there were places to go and people to meet so I’m finishing it up for this week’s entry.

After Q & A:
I’m afraid that I might begin to be known as the over-dramatic emotional one, but I’m going to take that risk because — while it’s probably very true, it’s totally worth it and it’s who I am and it’s what I do. I speak from the heart and rarely have a “filter” so consider yourself forewarned.

As my third Dreamforce draws to a close, the sidewalks are clearing, the halls of Moscone west begin to look deserted leaving almost no trace that we were even here for 5 days…I can’t help but feel a little bit emotional. I was traveling up the escalator this morning with some friends and we were discussing how awesome it was to be able to move about without bumping into everyone, it was also kind of saddening because it meant that it’s all coming to a close. In my logical brain, it seems NUTS — Salesforce is just a platform, a tool, how can I be so emotionally invested in something like this to the point of absolute sadness when Dreamforce comes to a close? But my emotional brain feels something quite different and it’s hard to zero on on the words to describe, but here are my rambling attempts to put it into words:

You’re expecting me to say community, but we’ve been there before and while that still holds true it somehow feels deeper than that. Yes there is a very passionate community behind this crazy thing we call Salesforce and that’s what makes it unique, but inside that community are groups of people that form bonds that are somehow stronger than what I believe the term “friendship” can express.

I was talking with a fellow MVP about a certain individual now amongst Salesforce ranks. As we were talking, she became somewhat overwhelmed with emotion about why we are all here, and how they’re so proud of this mutual friend. I told her that I could relate and that I even tend to get somewhat emotional talking about the community and it was a relief to me that I wasn’t the only one that can get choked up while reflecting upon these intricate, complex, but beautiful bonds.

I mentioned that this trip was going to be personal, and for me it was very, very personal. I got to know some incredible people that until this week I only knew “virtually.” I got to connect with some new faces and now I cannot imagine my life without being able to meet them for quick chat or even just a smile and share collective yawns. Now that Dreamforce has come to a close, I am going to have to be content with these virtual interactions, and they’ll help but will pale in comparison to sharing the same space, and being “in that moment” with that person. Eye to eye, face to face.

I never thought of myself ever as a people person, never wanted to BE one, but I am. I am so VERY much a people person. I may not initiate with a complete stranger but once engaged with someone, I’d like to think I am in that moment and I certainly do enjoy the interaction. Sometimes those moments turn into something deeper, you find yourself wanting more of those moments with that person or group of people, and before long — they become family. You light up when you get to say “hello”, and when you hug them goodbye a part of you leaves with them and while you’ll still be interacting — on a daily basis quite likely — it’s just not the same as being there with them in person. So yea, call me the over dramatic emotional one, I’ll take that and own that shit because it’s true. I’m emotional and I don’t think I’d ever want to be any other way.

After Returning Home (reflection):
Friday night for me was very emotional and for the first time I perhaps revealed said emotion to a couple of people over dinner. You see, when I got named as a Salesforce MVP, I was overwhelmed and merely attributed it to the fact that I wrote a silly song that happened to resonate with people. For some time afterwards a couple of my colleagues would “check in” occasionally and ask me why I think I was given that honor and when I’d start my reply with “Well I wrote that song…” I would get either a slug in arm or a “shame on you” look. But while standing in line in the Devzone I was listening to so my friend Jen talk about items in the upcoming release or features for the platform that I am not at all familiar with. I took that chance to once again point out how I didn’t understand why I’m an MVP, but her answer was crystal clear, and matter of fact. At the time of her reply I wasn’t “emotional” and it was an awesome answer, it wasn’t until I was explaining her answer over dinner to someone else that it really hit me and yea, I got a little “misty” when I repeated it: “Because when I tweet or DM you at midnight for help, you’re there.” That answer means the absolute world to me and even reflecting back on it now I feel like something has clicked.

So yes, I’m emotional — perhaps to a fault, but I’m thankful for those emotions (it means I’m alive & human after all — like everyone else), and I’m thankful for all of the relationships that have formed because of the Salesforce community and I wouldn’t trade them for the world.

[EDIT: At the suggestion of the legendary @ZacharyJeans I’ve added a few photos that bring home the “family” feel]

:wq!

# This Time It’s Personal

Shortly after Dreamforce last year, I talked about what I felt made the Salesforce world so different (hint, the community). I still believe that very much, and for that reason I’m looking forward to Dreamforce ’15 more than ever. I’m staffing the “Coding for Admins” booth in the admin zone on Wednesday from 10-Noon (PST). I hope to meet some new folks there and to help them out — not because that’s what is expected, but because that is what I enjoy doing.

I’m also looking to reconnect with those that I already know but don’t get to see often or at all save for events like this. For me — this is very personal. Many of these people are like those cousins that you love to hang out with but rarely get to see. Jenny Bamber (@Jenny_Bamber) recently released a “Unofficial Guide to Dreamforce”. I’d like to call your attention to page 7. On that page are five quotes. Three of these five are very similar. I’ll give you a second to figure out what the similarity is…go ahead….I’ll wait (screenshot below for the impatient).

Welcome back. Did you figure out what the similarities were? Three of those five quotes mention hugs. When I attending conferences, meetups, etc from other technology stacks, it was hard enough to shake hands, but “here” its like family. We hug, we laugh, we share stories both work related and personal, both happy…and sad. It literally feels like extended family (without that creepy uncle nobody talks about).

So this year, Dreamforce feels very personal for me and I’m looking forward to the stories whether happy or sad, the new friends and faces, the old friends….and the hugs.

See you next week!

:wq!

# How To Create A Sublime Snippet

Those of you who know me, know that I absolutely cannot stand using bloated IDEs for development work. My disdain for Eclipse started way back when I was a day to day Java developer. Most of my Java projects however were so complex with framework stacked up on framework that one absolutely NEEDED to use Eclipse to keep things sane. It became a daily ritual. Boot up, fire up Eclipse and walk away…I’m pretty sure if two or more devs showed up at the same time and fired up Eclipse that the lights in the building would flicker.

When I moved on from Java into lighter languages like PHP and Python, I switched to using gEdit (on linux), and sometimes even vi. One of the more powerful features of gEdit was something called “snippets.” Snippets were little chunks of text that could be “spit out” when they were triggered by typing a magic string of characters and hitting tab. I went snippet crazy for awhile, creating snippets that built case statements, if loops, sql queries, etc. I’ve now moved onto using Sublime Text as my editor of choice and thankfully, Sublime supports snippets as well. (Apparently Eclipse also supports snippets, but I’m not much for putting lipstick on a pig…but I digress).

Today, I’m going to show you how to create your own snippets for Sublime Text. The first thing you want to do is identify some block of text that you find yourself typing often. I suggest something that involves multiple carriage returns, parameters, etc. Sure you could write a snippet to spit out a simple if/else block, but I usually don’t bother with that since that takes me just a moment or two to just type out (and I haven’t really had the time to sit down and write any snippets anyway so maybe one day, I’ll write that).

Today’s example I’ll create a simple apex:pageBlockSectionItem snippet. When I type my magic characters, it will spit out the following:

```    <apex:pageBlockSectionItem >
<apex:outputLabel value="My Label" />
<apex:inputField value="{!myValue}" />
</apex:pageBlockSectionItem >
```

Granted that’s not a ton of text to write but A) let’s keep this simple shall we? and B) if we are building a large VF page, it might be easier for us to simply type: apbsi and fill out a few parameters when we want to add a section item.

To get started, open up Sublime Text and choose: Tools->New Snippet

That will spit out some default text for us:

Lets quickly walk through what those lines are asking for. The first line we care about here is the <content> line. This will be the actual content of our snippet. With the exception of the CDATA declaration and some placeholders for where we will be prompted for our input, this is the exact text that will be placed on screen upon typing your trigger text. As you can see, there is some strange syntax here like \${1:this} \${2:snippet}. These are tab stops. When our snippet pops up on the page it will put the cursor at our first tab stop (\${1:this}). This is where will we be able to insert some text. If we don’t enter any text at this tab stop, it will default to “this”. If we hit tab again the cursor will be placed at the second tab stop (\${2:snippet}). Again we can enter some text here or it will default to “snippet” — so the format is \${TABSTOPORDER:defaultvalue}.

Secondly we will want to specify the trigger text that will result in this snippet printing to the screen and doing its thing. This is done by specifying the value. (Currently commented out in the screenshot — I’m not entirely sure why it defaults to being commented out as I can’t imagine NOT having a text trigger, but I’m still learning). For our example we’ll use ‘apbsi’ so that whenever a user types apbsi followed by a tab, our snippet will show up.

You can also optionally specify a description and a scope. Description is self explanatory, but scope is not. I have my visualforce and apex code using HTML and Java respectively so if its an apex snippet I am writing, I set my source to source.java — if its Visualforce, I set it to text.html. (Its a sublime convention I guess…not *really* sure why one is source and the other is text but that’s what worked for me). Scope ensures that these snippets don’t activate in unrelated files. For instance, if I’m writing some python code and just happen to type in a snippet trigger for some java code, it won’t activate.

At the end of the day, I have this for my pageBlockSectionItem snippet:

```    <snippet>
<content>
<![CDATA[
<apex:pageBlockSection title="\${1}" columns="\${2:2}"collapsible="\${3:true}">
<apex:pageBlockSectionItem>
</apex:pageBlockSectionItem>
</apex:pageBlockSection>
]]>
</content>
<tabTrigger>apbs</tabTrigger>
<scope>text.html</scope>
</snippet>
```

Lastly, save the file. Ensure that you name it with an extension of sublime-snippet. I forgot to do this my first time through because I figured if sublime were smart enough to default my folder location, it would be smart enough to add the extension. Shame on me ;)

And now when I’m in a VF page and want to add pageBlockSection item, all I need to do is type: ‘apbsi’ and hit tab. While this is just a small example, having an army of these snippets built up can be a huge time saver for the more mundane bits of code we type on a day to day basis. Thankfully, someone seems to have created an Apex based snippet library already :) I’m still looking for a visualforce one though. If you know of one, let me know in the comments below or reach out to me on twitter.

:wq!

# My Top 5 Sessions for DF15

Keeping in the spirit of Dreamforce-based topics, today I will highlight my top 5 sessions for Dreamforce ’15. These are from my agenda and not by any means a “Best of DF”, but rather the ones that I’m excited for because they apply specifically to my interests/career path, and my idea of fun. So in no certain order:

1. Easy REST Integrations with Lightning Components and Salesforce1 (Tues. 3pm Moscone West, Developer Theater) — Its got two things that I’m a big fan of, Lightning components and REST. This session will apparently demo a marriage between these two hot topics that are near and dear to my heart.
2. Coding for Admins (in the Admin Zone, from 10am to 12pm) — Why? Because that’s my shift in the Admin Zone. Come on down and talk to me, hopefully I can help you with something that’s been throwing you for a loop? (See what I did there?). I’m very excited to be attending DF this year as a Salesforce MVP and have been looking forward to being able to help out. I’m so excited about this, I can’t really express it.
3. Marc Benioff’s Keynote (Wed. 1pm Moscone South) — I mean really, does anyone plan on missing this thing? I surely hope not.
4. The Developer Keynote (Thurs. 10:30 Moscone West) — I’m a developer, so #NoBrainer
5. The Admin Comedy Club (Thurs. 2pm Hilton, Union Square, Ballroom A) — With all the excitement & information overload, its nice to know that there’s a place to go where you can sit back, relax for 40 minutes and have a good laugh. This year, yours truly will even be participating. I can’t wait to see what we do, because — as of yet — I don’t know what we’re doing save for the fact that I’ll be debuting a new song (and maybe even a special guest singer — or two), live! So I hope I see you there :)

I’m looking forward to my third Dreamforce. For me it will be my third Dreamforce and likely my third completely different experience. This one should be the best yet! What sessions are you most excited for?

:wq!

# My Top 5 Must Haves at Dreamforce

Admittedly, I’m an over-packer. I pack all sorts of crap that I know I’m absolutely NOT going to need, but I can’t seem to help myself. However, there are some things that I absolutely cannot go with without. Here are my top 5 (in no certain order):

1. Comfortable Shoes — likely more than one pair. I’ve never done so much walking in my entire life. Last year I got one of those little Jawbone devices that they were giving away in the expo and at the end of my first full day with it, I was over 22,000 steps. I’m starting to get too old for this!
2. My Mophie standalone phone charger. Your phone will be struggling with battery life in the area, if I had two of them, I’d bring two of them. Alas, I have only one so it will have to do. I’ll turn off any un-needed services and operate on the lowest level of brightness if I have to, but having this battery backup is a life saver!
3. Laptop — call me old fashioned but yes, I still lug around my laptop at events like this. (Mainly because my iPad is a first-generation one and has pretty much reached the end of its useful life for me — and I’m cheap). Believe it or not, you will have some downtime or will “need” some downtime. For a developer like me, that downtime comes in the form of hacking code or further learning (Trailhead anyone?), but I like to find a bean bag near an outlet and zone out for a bit….speaking of power outlets:
4. Power Strip — it will add a little bit of weight to my bag for sure, but I believe Brian Kwong mentioned at our user group that if you are the person with a power strip at Dreamforce, you will be one of the most popular people on campus. What a fantastic way to meet new people! So this year, I’m giving that a shot.
5. My Guitar — I never like to be far from some source of music creation. I never know when lyrics or melodies will pop into my head. Its also my comfort zone. Its like a comfort food for my soul, and a way to decompress at the end of the day, or whenever I need it. Luckily for me, I have a folding guitar so its not a big bulky thing. I doubt I’ll be carrying it around all that much but hopefully it will find its way to admin zone with me at some point. I did bring a mandolin & a travel guitar my first year and touched them once each, so I may not even get to use it, but just knowing it is there is comforting.

So there you have it! What are your top “Must Haves” for Dreamforce this year?

And also: Is It Dreamforce Yet?

:wq!