Trailhead Lightning Module is a Major Charge!

If you haven’t heard about Salesforce Trailhead by now, allow me to help you out from underneath that rock (I kid because I care).

Salesforce Trailhead was launched at Dreamforce ’14 and if you haven’t tried it out yet, its incredibly cool. I’ve been in a number of different communities and aside from Python/Django (who gets an A for effort), nobody has such a great intro to a platform. Salesforce Trailhead is heads and tails above any “tutorial” for a learning a platform anywhere.  Its professionally put together, it quizzes you on what you’ve learned, it connects to your development org (it helps you set that up too) and keeps track of your progress, and actually rewards your progress along the way with fancy badges.

You can start at the beginning and work your way through the platform or you can pick and choose modules at will. Originally I was going to walk through module by module but since I have the attention span of a gold fish and like to jump right into shiny things, I quickly finished my first module so that I could jump into Lightning Components. I’m not quite finished with it yet, but I’ve made it through 69% of the exercises and already have greatly improved my initial grasp of the concepts. (Three more to go and I get my badge!)

If you’re not quite sure what Lightning Components are, its basically the next step in Salesforce development. Its really more of a framework made up of re-usable and extendable UI components that you can use to work with your Salesforce data. These components can hold other components and they can be extended to create custom components that work on the Salesforce1 platform. At DF14 when they were announced you could only write Single Page Applications, but will soon have the ability to extend existing Salesforce1 screens. They’re javascript based on the front end and use an MVC type of approach to building the UI. That javascript then talks to Apex on the Salesforce side.

Back to trailhead: The Lightning Components module starts out with your basic Hello World application and gets you on the ground running right away. The challenges aren’t so difficult that one wants to just toss it out, but they also leave you with plenty of room to stretch your own ideas and play some “what if” scenarios. (Actually my last unit was on the event handling and when I was done I tried to run the example and had some unexpected results, but with a little poking I was able to figure out how to get it functioning. As it turns out, the next chapter was going to cover what I’d just done (…its like they read my mind!)

The module moves on to creating a “reservations” type application where you create a form where users can “register for an event.” So its an completely relatable topic as well. Often times some examples on other sites are so out there, and so “basic” that you really don’t learn much. Not the case here. I’m not sure how they did it, but whatever it is they did, they did it right.

You can tell these modules are put together with a well thought out execution plan. The lightning components module especially seems to have most definitely been put together by developers for developers, but yet they are simple enough that even non-developers can jump in and start exploring (though some knowledge of javascript is probably advantageous).

Trailhead itself keeps you coming back as well. The gamification concept with the badges makes you feel like you are getting somewhere. While I haven’t scored by Lightning Components badge yet (I do have a job ya know…), its the desire to have that little logo on my profile and the ability to tweet my achievement out to the world that keeps me driving forward, all the while tricking me into learning something. How dare they teach this old dog new tricks! :)

In a world that is quickly going mobile, Salesforce is poised to lead the way and learning Lightning Components will put you at the forefront of this tidal wave. So grab a surfboard and paddle over to Trailhead and prepare yourself for the future.

I’d love to help you along the way if I can, so if there is something you’d like me to try and/or talk about or do a “deep dive” on, let me know in the comments.

:wq!

Testing Tidbits

Today I’m going to talk about two of my go-to “tools” (for lack of a better term) when it comes to testing functionality in any Salesforce org that I do work in. I don’t always do these things…(but when I do….*never mind*) though I’m starting to do them more often and its been working for me.

The first of these items also comes up often in the #salesforce IRC channel as well and its been talked about in many places but I see this brought up so often that its probably a good idea to mention it yet again.

Use Hierarchy Custom Settings to “short circuit Validation Rules, Workflow Rules and even Triggers. (If you aren’t sure what Custom Settings are or what they do, then watch this video[1]). These are very valuable not only for day to day operations, but also in my unit tests. The idea for unit testing is to test small chunks of functionality. Sometimes things like Validation Rules can get in the way of that. If you’re testing a bit of code that operates on an opportunity, but that functionality doesn’t care whether or not certain fields are required, use the Custom Setting to turn off the Validation Rules that would fire so you don’t have to populate a bunch of fields that you aren’t testing/don’t care about.

For example lets say we have some validation rules in place that ensure a specific group of fields are filled out on an opportunity. Further more, lets say that we are testing a trigger that will create some child object(s) when that opportunity is created/updated, etc. If all we really want to test is whether or not that trigger works when an opportunity is inserted, why run validation on that opportunity? (Unless of course those child objects depend on these fields, lets assume they don’t for now). If our Validation Rules have the short circuit in place, our test code can turn them off in our test to ensure we don’t get errors. This is also valuable because IF we are breaking our tests down into small bite-sized chunks, when someone comes along later and adds a Validation Rule it won’t break our test. (Again, this will assume those creating the Validation Rule are inspecting our Custom Setting first, so it will take some cooperation). So lets say we have a Custom Setting called Admin Settings and a checkbox on that custom setting called Run Validation Rules. In our test setup, or in the test itself we can simply do this:

Admin_Settings__c settings = Admin_Settings__c.getInstance();
settings.Run_Validation_Rules__c = false;
insert settings;

Now when our test code runs the Validation Rule will be skipped. If we get in the habit of doing this for all of our Validation Rules, Workflow Rules, etc. then we can keep things pretty clean and not so brittle. Its never a nice surprise when you go to deploy a changeset and tests start failing because someone added a Validation Rule in production! Of course there are times when you are testing larger chunks of code or functionality and you’ll want to ensure that these rules run. In that case, instead of setting Run Validation Rules to false, just set it to true and you should be good to go.

You can also use this short circuit in triggers by creating another checkbox field on Admin  Settings called Run Triggers and in your trigger inspect that field to see if its true or false:

Admin_Settings__c settings = Admin_Settings__c.getInstance();
if(settings.Run_Triggers__c == true) {
    doIt();
}

You could even get really specific and create custom settings for different objects. Maybe don’t want to short circuit all VRs or WFRs. You could get more specific with fields like: “Run Opportunity Validation Rules” etc…

The second tidbit isn’t necessarily Salesforce specific as you can use this all over the place. I was actually surprised by the number of people that didn’t know you could do this so that’s why its here.

Take advantage of Gmails flexible email addresses.  For instance, if my email is thedude@ihatetheeagles.com, I have several ways that emails can be addressed to me:

  • thedude@ihatetheeagles.com
  • the.dude@ihatetheeagles.com
  • the.d.ud.e@ihatetheeagles.com (etc)
  • thedude+test1@ihatetheeagles.com
  • thedude+myappname@ihatetheeagles.com (etc)

You get the idea. I’m not sure if other email services allow this and if so great, use them. I use them to have unique email addresses on my test users/contacts etc but still have all messages come to my email address when testing. You could potentially use this as a form of getting a stream of messages on a per-app basis and applying a filter in gmail to automatically archive/apply label to messages coming in to thedude+myapp1@ihatetheeagles.com to have groups of messages filtered out by app. If I’m doing a ton of testing and messages that are coming to me are coming from different areas of the app, I can use these addresses even to figure out what app, what part of an app, etc the messages are coming from.

What are some of your favorite goto nuggets for testing, or anything for that matter? As always if there is something you perhaps want me to deep dive on, let me know in the comments.

P.S. I actually love the Eagles…

 

[1] video found on youtube, author: Shannon Hale (@shannonsans)

:wq!

 

My Top Five Parodies for Salesforce

I  get asked quite a bit what song is coming next. I’ve helped others write several parodies of existing songs and while I don’t generally perform the parodies, here is a list of what I have coming up next. I may or may not be performing them on my own, but we’ll see:

Top 5 Salesforce parodies in the works:

5) You’ll Be a Closed Opp Soon (Girl, You’ll Be a Woman Soon)

4) Valdiation Rules (California Girls — Katy Perry)

3) Ben-i-off (Shake it Off — Taylor Swift)

2) I Only Added One More Rule (Only Wanna Be with You — Hootie & the Blowfish)

1) It’s Friday, Lets Deploy (It’s Friday I’m in Love — The Cure)

I was so excited to do the It’s Friday, Let’s Deploy that I couldn’t wait to do it, so without further delay: enjoy!

 

:wq!

Wow! Thank You!

Last Thursday I was met with some very good news. I am now a Salesforce MVP, class of Spring ’15!

I think its all still settling in but wanted to take a moment to thank everyone who nominated me. I’d like to thank the current MVPs who were part of the process as well, if it weren’t for the encouragement of my MVP mentor Vamsi Krishna, and other MVPs who were there as a sounding board for me (Bill Greenhaw, Sarah Deutsch, Brian Kwong to name a few) I’m sure I’d not have had the chance to have this experience.

Its very humbling. I interact with a number of superstars in this community who are certainly MVP material and here I am — one of them. There truly are not words to fit the occasion. (Actually, there *are* some words, but I’m still putting them together).

Now I must ask you all for a favor: If there’s something I can do to help give back, something you’d like to see me try (e.g. put together a blog post about a specific topic, maybe even speak on a certain topic perhaps — which scares the bajeeezus outta me), anything I can do, please let me know. Hit me up on twitter, even facebook, email, here in the comments, smoke signals, whatever — I’m here. I don’t like to make it obvious, even downplay it a bit at times, but I LOVE interacting with the community, so don’t be shy :)

Again 1000 times thank you!!

 

:wq!

 

Find Your Mantra

Recently I was asked a question to describe what exemplified me as a coder, preferably with an example of code. It was odd, not something I’ve ever really thought about. I write code and attempt to leverage the pluses of a given framework and work around the minuses. I don’t have one “goto algorithm” for sorting things, or a given methodology that could be described in words let alone code, so I got to thinking, and thinking, and thinking. All I came up with was one simple rule: “Write easily digested code.”

I’ll be straight, I’m 40 years old, been in IT for over 20 years, and I’ve not the time nor desire for flexing my coding muscles by showing of my implementation of  the “modified pre-order tree traversal” algorithm. I’m not gunning for a job at Google, or looking to be a star on Top Coder, etc. I’m here to “get shit done” in a sensible, maintainable, and easy to understand way. Perhaps its my python background that taught me that there is elegance in simplicity and much value to be had in explicit versus implicit code. Sometimes that may seem like the long way around but in the end, even the most “showy” of developers wind up appreciating something simple. We stare at problems all day, one of those problems need not be deciphering someone else’s “mental inspirations” in their code.

MOST of us aren’t coding to save lives, put someone on the moon, or write high performance platform games. MOST of us don’t have to worry about the “Big O” of a given algorithm. I save that for the people *way* smarter than I am. I rarely have to dust that sort of skill set off and when I do, you can be darn sure I will have no less than 22 tabs open in Google walking me through it.

At the end of the day, when I move on in this world, whether figuratively or otherwise, I want whomever inherits my code to not have to sit back and scratch their head, or re-read a section of code over and over to make heads or tails of it.

I’ve talked about writing clean code before, but this goes even beyond that a little bit. Its really one of those things that are hard to talk about until you’ve seen it. I’m always striving to make my code simple to comprehend, but not just by seasoned programmers but by the young intern that’s gonna be inheriting your code someday.

I’m not exactly sure the person I was talking to was pleased with my answer, it was probably nowhere near academic enough to hold their interest and probably seemed like a cop-out. It may be a cop-out to them but for me, its sort of turned into a mantra: “Write simple and easily ‘ingestable’ code”

 

:wq!

Just For Fun

Time wasting links edition:

Nothing techie today folks. Sometimes we need a “checkout,” time to take a step back, take a breath and reset. Sometimes our minds get so clouded we forget to have fun. So lets have some fun shall we?

Since music is my release my first sidestep is this: there’s another Salesforce singer in our midst: Shane McLaughlin (@MShaneMc) so welcome to the show Shane. :) (admittedly I’m slightly jealous of his 330 views!! “Ima let you finish but….”

Continuing with music, for karaoke lovers: did you know you can sing karaoke online? Well you can: and I did. If only I had more time to waste! (It even lets you do duets with  a stranger #harmony!!).

Then there’s this magnetic putty stuff: #creepy — reminds me of the blob but yet I still wanna score some. Not exactly what I’d do with it aside from creep my children out, maybe there’s some fun Halloween type thing I could do with it…

And Office Space has come full circle. How very meta. Whatever happened to Michael Bolton anyway? Either of them?

Oh, sorry back to music for a moment: I KNOW this guy!! He’s awesome. And I seriously don’t know whats wrong with Pharrell & Christine, “Is this thing on? Hello? Testing 1,2,3!!” Oh and go checkout his old band (and I went to high school with his bandmates Andy & Joe Wilson).

Anyway — alas I must work.  Projects to start, code to write, and sunshine in my window to enjoy (at last!)

:wq!

 

 

 

 

 

 

Developer with Admin Tendencies

Since the release of Spring ’15, I’ve had the opportunity to use the Process Builder on a couple of projects. When you’re a developer, you tend to see solutions “in code” more often than not. We think in code, we love to write code, its just what we do. With this latest release however I took the opportunity to write a few processes where in the past I would have written triggers and I must say, its pretty slick thus far.

In order to get a personal comparison, I wrote a trigger and supporting utility class first which took me a little under 30 minutes or so, including unit testing.  (Sadly I neglected to write down the lines of code, but it wasn’t much really as this was a simple record creation process with some basic criteria).

Then I decided to replace that trigger with the Process Builder (or as some people are suggesting, PB & J, Sandwich, etc but I digress). Upon firing it up for the first time I was impressed. The UI was clean and it was pretty self explanatory. Perhaps it was the fact that I’d already worked through the logic once when writing the trigger version, but I had the Process Builder version saved and activated in under 10 minutes and it was doing everything my trigger was doing. Color me impressed. (There were/are still a few minor bugs — like a drop down list that was rendering too low on my screen to be seen, I had to shrink my browser view to fit more on it, but that wasn’t too bad).

Admittedly, I should have been checking this out in a dev org long ago but as stated, I’m a developer, I think in code. I was largely focused on learning what I could about lightning components (and I’m still way behind) in my minimal free time, so Process Builder just kinda fell to the side for me.

I was listening to the @Code_Coverage podcast yesterday over lunch (episode 18) and hear a brief mention of a team of Java devs that basically rewrote the entire authentication process in code (or something to that effect — I was coding at the time). Sadly, I think this is something that developers are apt to do more often than not, we tend to ignore the pieces of functionality that could be done with clicks. However, Salesforce has given us some pretty sweet tools and I’d like to think I’m becoming more of a developer with admin tendencies. After all, Apex Commandment #3 is “Thou shalt have a happy balance between clicks & code.” This is something that the platform makes easy for us and we should embrace these tools more often. When I first started — everything was code. After two years or so under my belt I’ve seen a transformation. I still have the internal fight with myself “I can just knock this out in code, I’m in here already” and that voice used to win often — its winning less and less and I’d like to think I’m finding that happy balance.

So use the tools, find that happy balance and become a developer with admin tendencies :)

 

:wq!

Have You Nominated Your Hero Yet?

It’s that time of year again. No, not the time to spend money on cheesy I love you cards, and calorie filled fake chocolates…I mean its time to nominate your Salesforce Community Heroes for MVP status! I’ve cast my vote(s) for some very deserving folks. Nomination is very important. Its well within your control to see the community become what you want/need it to become by selecting those you want to see help drive the passion behind the community! So what are you waiting for…just do it!

Having trouble choosing? Not sure what makes a good MVP? I’ve talked about here before.

 

:wq!

When an Email Template Just Isn’t Enough

Sometimes your users need to send an email from within Salesforce. Most of the time the standard Send Email button will suffice. Other times however, your needs are more specific. For those times, developers often resort to using Visualforce email templates which can certainly meet just about any need. However, the drawback here is that the email content now lives in code. Being good developers, we don’t want our admins to have to worry about digging into code for things like this — unless they really want to — so we try to come up with a way to make the content of the email accessible. This was my exact requirement and here’s what I wound up doing. The code herein is very specific to the requirement in question but could be generalized a bit to make it more flexible or reusable (which is something I may just do at some point, but alas — deadlines. @Codefriar has already done some pretty cool stuff here.).

Here was my approach:

The Template:

I created a new Email Template just as one would for use in workflow email alerts etc. I then created a custom settings to store the ID of this email template in this particular application’s custom settings. I will use this ID later to get the ID of this template in my apex class.  In the content of this email I included the merge field syntax (more or less because it was familiar to people) for the fields that I knew I was going to be including later.  In the end I wound up with a template that looked something like this (any client identifiable content has been replaced with BLAH BLAH BLAH — I’m so creative…):

Dear {!Contact.Salutation} {!Contact.LastName},
I am pleased to attach the final BLAH BLAH BLAH document between {!Opportunity.Account} and the BLAH BLAH BLAH for your records.

BLAH BLAH BLAH is proud to work with {!businessTypePlural} such as yours to fulfill new opportunities in BLAH BLAH BLAH.

Thank you for your commitment to your employees, your community and the state of BLAH BLAH BLAH.

BLAH BLAH BLAH is always looking to improve our services. Please take the time to fill out a brief satisfaction survey using this link:

{!surveyLink}

Sincerely,
Some Person at BLAH BLAH BLAH

Some of those items I could have set using the standard setTargetObjectId, setWhatId methods available on Messaging.SingleEmailMessage, but those wouldn’t get me to some of the other data that I needed. So instead, I used the template merely for its body content and manually performed string replacements in my apex class on that body like so:

public EmailTemplate emailTemplate {
        get {
            if(emailTemplate == null) {
                Survey_Settings__c settings = Survey_Settings__c.getInstance();
                if(settings != null) {
                    emailTemplate = [SELECT Id
                                     , Subject
                                     , Body
                                     , HtmlValue 
                                     FROM EmailTemplate 
                                     WHERE ID = :settings.Contract_Email_Template_ID__c];     
                }
            }

            //send in the Contact for salutation purposes
            if(this.selectedContact != null) {
                Contact c = this.oppContacts.get(selectedContact);
                if(c != null) {
                    if(c.Salutation != null) {
                        emailTemplate.Body = emailTemplate.Body.replace('{!Contact.Salutation}', c.Salutation);    
                    } else if(c.FirstName != null) {
                        emailTemplate.Body = emailTemplate.Body.replace('{!Contact.Salutation}', c.FirstName);    
                    }
                    
                    emailTemplate.Body = emailTemplate.Body.replace('{!Contact.LastName}', c.LastName);
                }
            }

            emailTemplate.Body = emailTemplate.Body.replace('{!Opportunity.Account}', this.opp.Account.Name);
            emailTemplate.Body = emailTemplate.Body.replace('{!businessTypePlural}', this.opp.Account.Business_Type_Plural__c);
            
            return emailTemplate;    
        }
        set;
        
    }

Much of the above, (if not all) could have been achieved by just sending in my contact. I could have gotten most of the necessary information from there, however — in so doing, the body of the email would have been rendered but I still don’t have all of my information, particularly my survey link. I wouldn’t have my survey ID yet either as that doesn’t get created until my end user clicks send. By then it would be too late for me to stick the survey link since the email message would be already packaged up. (I did try this, before going this route but ran into some odd issues getting my link in the email message, so I backed out and moved forward with this plan). Add to that the fact that I wanted to show the content of the email WITH the substitutions in place to the end user for review.

Lastly, once the user has selected their attachment and has proofread, perhaps even modified the message (minus the link since it doesn’t exist  yet) they click send. I then save all the necessary objects, including my survey and stuff that into the email message before calling my sendEmail method.

private Messaging.SendEmailResult[] sendEmail() {
        Messaging.SingleEmailMessage msg = new Messaging.SingleEmailMessage();
        List attachments = new List();
        Messaging.EmailFileAttachment contractFile = new Messaging.EmailFileAttachment();
        contractFile.setFileName(emailFile.name);
        contractFile.setBody(emailFile.body);
        attachments.add(contractFile);
        msg.setFileAttachments(attachments);
        msg.setSubject(emailTemplate.Subject);
        msg.setToAddresses(new String[] { this.oppContacts.get(selectedContact).Email});
        msg.setHtmlBody(emailTemplate.Body);
        Messaging.SendEmailResult[] result = Messaging.sendEmail(new Messaging.SingleEmailMessage[] {msg});
        return result;
    }

Which gets called from this hunk of code in my save method on the controller.

Survey_Settings__c settings = Survey_Settings__c.getInstance();
                if(settings != null && settings.Customer_Satisfaction_Survey_URL__c != null) {
                    String surveyUrl = settings.Customer_Satisfaction_Survey_URL__c + '?aid=' + this.survey.ID;
                    emailTemplate.Body = emailTemplate.Body.replace('{!surveyLink}', surveyUrl);    
                }   

                //send the email
                emailTemplate.Body = emailTemplate.Body.replace('\n', '
');
                Messaging.SendEmailResult[] result = sendEmail();

I then manually create an activity that logs this message and includes the body of the email in the description field of the task. The task is set to Completed in code so it goes directly to Activity History.

In the end, the solution provides full access to content to the admin, and full control over the flow complete with some extra automation that they couldn’t get out of their old process.

Hope this helps should ever find yourself in a similar situation…

 

:wq!