Thursday, February 2, 2017

[Salesforce / Javascript] Visualforce tips for Javascript nerds


No secret I love Javascript.

It's messy to the right point, it can be quick and dirty, it can be elegant, it can be wathever you are: your Javascript code can be a mirror of your personality.

And what's better that putting together 2 things I like the most?

Yes, I'm talking about Salesforce and Javascript.

Javascript is the core of the new Lightning framework but since the birth of S-Controls (now deprecated) and Visualforce it's been an importanto tool to expand the standard Salesforce platform.

What do you have to know before starting your Javascript journey with Visualforce?


Use zipped static resources for your scripts


Put all your JS files into a zipped static resource, this way you have aboslute control over the place where files are stored and have no problem finding them.


Use the apex:includeScript


If you use the HTML script tag the resources can be loaded more than once and this can lead to unexpected errors.

Think you are using jQuery and Bootstrap and your page loads them in sequence.

In the same Visualforce you also use a custom Visualforce component which loads jQuery itself: what's the outcome? Bootstrap is simply erased from jQuery plugins.

The apex:includeScript component loads all the JS files only once, avoiding this kind of conflicts.


Use only one version per library


This is the same scenario of the previous paragraph.

If you load, e.g., jQuery 2 in one point and jQuery 3 on another place, this could lead to conflicts and strange behavior.

Keeping you library version on a static resouces allow you to get the right library version across all Visualforce page and components.


Use jQuery as much as you can


You'll be using Javascript because you'll want to create a slick, modern and responsive UI, so why reinvent the wheel?

Some good programmers still lack in jQuery knowledge, if you are one of them keep some time to study the bases of the library and I assure you won't regret it...and you can be sure you'll have really few problems for compatibility on different browsers.


Give all your components an ID / class name


When you develop a new Visualforce page take few minutes more that necessary to give all your components a recognizable html ID.

<page id="thePage">
 <pageBlock id="mainPB">
  <apex:pageBlockSection id="customerDataPBS" rendered="{!showCustomerData}">
   <apex:pageBlockSectionItem id="csDataNamePBSI">
    <apex:outputLabel id="csDataNameLBL">Name</apex:outputLabel>
    <apex:outputPanel id="csDataNameVAL">
     <apex:inputField id="csDataNameINP" value="{!account.Name}" />
     <apex:commandButton id="refreshCsNameBTN" 
          value="Refresh Data..." 
          action="{!refreshAccountName}"
          rerender="csDataNameVAL" />
    </apex:outputPanel>
   </apex:pageBlockSectionItem>
  </apex:pageBlockSection>
 </pageBlock>
</page>

This will ease your life if in the near future you decide to use Javascript to access the page's markup.

Remember that IDs are automatically calculate by the Visualforce render engine, so if you want the exact ID you can use the $Component global variable, so if you want to access the apex:inputField on the previous code:

document.getElementById("{!$Component.thePage.mainPB.customerDataPBS.csDataNamePBSI.csDataNameINP}");

But I recommend not to use this way.

This is not incorrect but as you continue your Visualforce development (sometimes the customers you work with don't know what they actually want till they want it!) you can change the UI, moving sections on the page, so the ID chain can change over time.

That's why you can use the "ends with" operator with jQuery to get an HTML component:

var inputField = $('[id$="csDataNameINP"]');

That is easier. The only thing is that you must be sure that you only have one and only one component with that ID.

Sometimes I use class names rather that ID, so for example:

<apex:inputField class="csDataNameINP" value="{!account.Name}" />

This way I don't care about ID generation and go directly with searching for a specific class name.

var inputField = $('.csDataNameINP');

That is even clearer (this is something I usually do and I like the syntax but it is not a best practice).

Keep coding and may the Force.com be with you!

Monday, January 23, 2017

[Salesforce / Git] git commit -m "Salesforce"

Why Salesforce developers and admins should use Git and some of the best tools to help you do so.


I'm opening this (hopefully) wonderful 2017 with a guest post about a subject I really love, that is Version Control in Salesforce.

Alex Brausewetter of Blue Canvas contributed this guest post. He is a founder of Blue Canvas - a company that makes version control and CI solutions for Salesforce developers and admins. Prior to starting Blue Canvas Alex built the Salesforce integration for Cloud9 IDE.

A Brief History of Git


Software development changed forever on a humble weekend in April 2005. Linus Torvalds, creator of Linux, was getting annoyed with his the version control system he was using to work on the Linux kernel. They were using a proprietary source control management (SCM) system call Bitkeeper. Legend has it that the notoriously caustic Torvalds and the commercial company that owned Bitkeeper started feuding that spring. Eventually, Torvalds knew he could do a better job himself and went off for a marathon coding session in which he built an entirely new version control system. He named the tool Git after himself (“git” is apparently British slang for an unpleasant person).

Git didn’t catch on right away though. It took until the founding of GitHub in 2008 before it really took off. GitHub provided added value on top of Git because it created a hosted service and user interface that made Git much more accessible. The company was founded in 2008. One year later over 46,000 public repos were hosted on GitHub.


Why Developers Love Git


Today, Git isn’t just for open source projects though. Major enterprises use it regularly.

Software developers in large and small companies love Git because it’s a unique and simple source control system.

Git is very fast - it was written in C - a low level language that can move extremely quickly. Unlike previous version control systems, Git also allows you to work offline. It’s also fully distributed so no one server hosts the code.


Git and Salesforce


Probably the most popular thing about Git though is it’s collaboration tools. And it is these tools which make Git the ideal version control system for Salesforce.

Salesforce is one of the world’s great software development platforms. There is so much you can do with the platform. And you don’t have to be a traditional developer to make great applications with Salesforce. So many people can be involved with a Salesforce project: developers, Awesome Admins, business analysts, product managers, sales ops managers and so many other diverse types of roles can work together to create great applications with Force.com.

Git is a great tool for helping all of these diverse groups collaborate on a code base. It prevents developers from overwriting each other’s work and handles merge conflicts. With Git you can do code reviews and have a picture of who has changed what at all times. You can even use “git blame” to see the specific ways in which a file has changed over time. Who wrote this line of code and when? It’s extremely useful for debugging.

Git also unlocks the power of CI for Salesforce developers. Git facilitates the kind of best practices that make you feel comfortable pushing code to production more frequently. This is good for users because they are getting new features more quickly. It’s also great for hiring developers because developers love seeing their work live in production as soon as possible.


Tools for Using Git



That said, Git can be challenging to use. Here are some of the best tools that make it easier to use.


SourceTree


SourceTree is a free tool from Atlassian that acts as a graphical user interface (GUI) for Git. Most of the time developers use Git on the command line. But many Git commands can be cumbersome and repetitive or even unintuitive. SourceTree cuts through all of that by providing a simple interface for Git commands. It allows you to push, pull, merge, fetch, clone, rebase and so many other Git commands through a simple, well-designed interface. Oh and did we mention it’s free? Many Salesforce developers are already leveraging SourceTree today to make their Git experience smoother.



GitHub, GitLab and Bitbucket: Hosted Git Services


Today it’s not uncommon to hear about GitHub before you even hear about Git itself. That’s because hosted Git solutions provide such an intuitive and wonderful way to leverage the collaborative benefits of Git. GitHub, Bitbucket and GitLab are all great tools. All provide added features like Pull Requests and commenting, as well as save you the trouble of having to host and maintain your own Git server. Which service you prefer is a matter of personal preference but all are worth looking at. GitLab and Bitbucket both also offer CI services which can be useful for Salesforce teams looking to automate their deployment pipeline.


SCM Breeze


SCM Breeze is a lesser known tool but it’s really nice. SCM Breeze is essentially a series of command line aliases for Git which make typing commands much faster and simpler. Instead of typing “git commit -m ‘my commit message’” you can simply type “gc -m ‘my commit message”.

Even better, when you are adding files you can simply type “gs” for “git status” and see a list of all files which have changed since your last commit. And instead of typing “git add ” for each file, you can for example type “ga 1-10” and it will stage all ten of your files for commit. You can even cherry pick files by typing “ga 1-4” and “ga 6” and “ga 9” for example.



Blue Canvas


Finally, there is Blue Canvas: a hosted Git implementation designed specifically for the Salesforce platform. Blue Canvas is version control for Salesforce. It automatically picks up changes that are made on your Orgs and commits them into Git. It will even pick up declarative changes so no one needs to learn Git on the command line if they don’t want to. Everything is synced in Git in real time. Developers can access their code base and refresh their local environments using “git pull”. To learn more check out: https://bluecanvas.io/.

Monday, January 16, 2017

[Salesforce / Lightning] Of the #Lightning afraid be not!




I was introduced to the Lightning world at its very beginning by Jeff Douglas when I was an active member of the Top Coder community.

At that time there were soo few standard components, no way to add a Lightning app / component in a Visualforce Page or easily integrate Lightning with your existing CRM.

Plus it was so hard to make it work, no documentation, no examples, no debugging, but you could feel the beginning of something that would have innovated the platform.

In months the set of components exploded, the posts about Lightning become more and more common, people started sharing their discoveries, trailhead modules were added and the Lightning Design System allowed developers to give their apps the right look and feel.

So what do you need to finally become an expert of this awesome technology?


If you are completely unaware of what Lightning is, start with the Lightning Tralihead Modules:


Once you have a good overview on the technology I suggest to fall into the official lightning guide (always up to date): here you will find everything about the framework.

This is were I first learnt all, well written, easy to understand, covers the whole framework...and it's free!

Have also a look to the Lightning Design System official site: I suggest you to use this library to make your components as much "Salesforcish" as possibile for a perfect UI experience.

Feeling an expert now?


The next step is to develop something unique and amazing with your new set of skills.

I've written in the past years a couple of custom Lightning components (browse here), and this is the good way to master the technology: pick a use case (it can be even a simple component like a progress bar or a related list component) and try to port it in Lightning using the Lightning Design System.

At first you'll feel a bit uncomfortable but as long as you keep coding you'll get more and more confidence with the framework and learn more and more tricks, understanding a new way of developing in your CRM.

Don't be afraid, you'll never get bored of it, I'll just get in love with it and appreciate a new and different way to think code.

If you've never developed in Javascript you can be a bit puzzled at the beginning, but I guarantee this new way of developing in the platform will increase your programming skills to a new level.

This does not mean you'll forget all about Visualforce, some customers still don't use Lightning so the marriage Visualforce + Apex will continue for years, but even if you won't have any chance to use Lightning with a customer's project, there is no reason you should not start learning and mastering it!

Next step?


Open your Tralihead account and start learning Lightning, you won't regret it ! (MVPs never lie!)

Saturday, September 24, 2016

[Salesforce / Chrome Extension] The ORGanizer: the best Salesforce Chrome extension EVER!



TL;DR Download the ORGanizer Salesforce Chrome Extension

Have you ever got lost in your own browser between Salesforce tabs?


Have you ever lost a password?



Have you ever lost a page name / link?


Have you lost your mind using the Developer Console window?


If you have answered YES to the above questions, now it's time to SAY NO!

A new Chrome Extension is out there to help you on your daily ORG management!



Download the ORGanizer Chrome Extension, reported to be
the best Salesforce Chrome Extension EVER!!!


Can't wait?

Go to salesforce-organizer.enree.co and discover all its incredible features!


Never get lost in your own browser between Salesforce tabs


Never forget a password



Quickly and easily find all the links you need



Powerful tools inside every tab

Download now the ORGanizer Chrome extension from the Chrome Webstore!

Tuesday, September 13, 2016

[Salesforce] I wanna be the very best (Salesforce Developer), do you?



I'm sure you do or you'll do after reading this post.


When I started working on Salesforce in 2009 in WebResults (an italian Salesforce Platinum Partner), and at that time I was not aware of what Salesforce actually was.

I thought it was just a coding platform, similar to the one I used to work with in my post-degree experience, with a proprietary language and a lot of point-and-click stuff.

I thought it was my first occupation on my new job and that after a while I certanly would have switched to Java or .NET in few months.

I thought I needed a lot of time to master the platform.

I thought I needed to study over books and guess by myself the solution to whatever problems I may have found, hoping a help from Google.

You know what?

After about 8 years I'm still here talking about Salesforce ahd telling people how awesome it is!


I love coding, I started when I was a child because I was fascinated on how a program worked and how an "IF" statement could lead to a window, a button or whatever you see on your laptop screen: I bought a C++ "brick-book" and finally I understood how lines of codes translates into "screen things"...and I have to admit it's been quite a revelation (I still remember the feeling of power).

This means I love trying new technologies and making them work: I'm not like "the Guru of language X" because I love switching between technologies and find ways of using them whenever possibile.

You can think that Salesforce, as a proprietary platform, is strictly closed to its language and standards but... SUSPANCE...it's the exact opposite my dear reader!

By working with Salesforce I had the chance to put my hands on various languages and standards, from Java to NodeJS, from SOAP to REST, from jQuery to AngularJS, browser extensions, Heroku apps, version control, command line apps...I know it seems crazy but in the last 8 years I've produced thousands of lines of code and a great part of them is pubblicly avaiable on my GitHub account.

Why I'm talking about my GitHub account? Am I that pretentious?

Because the greatest quality of the Salesforce world is that you can find all kind of stuff open sourced, from apps to reusable components (e.g. DeveloperForce Github profile).


And what about the documentation?


You have no need to buy anything, you can find everything online on Salesforce Docs site, thousands of pages written by Salesforce for you to learn every little aspect of the platform...if you still like reading on your books you can even print the docs' PDF or even buy awesome books written by awesome developers!

And what about the community?


Salesforce community is AMAZING!

The entry point is the developer.force.com site: everything you need to start learning to be an awesome Salesforce developer is there!

The community counts on thousands of Salesforce developers, admins and users who share their experience on Forums, the Success Community (a place where you can find people, groups, partners), a dedicated Stack Exchenge community, thousands of Facebook and LinkedIn groups, coutless Twitter discussions, a dedicated #askforce Twitter hashtag to ask for help, blogs all over the net (click on Salesforce Blogs to get a glimpse of the most famous Salesforce blogs...and yes there is even mine), publicly acclaimed MVPs (Salesforce Most Valued Professionals, people awarded for their dedication to the Salesforce cause, and again I'm produly one of them).

And did I mention Trailhead?


Did you get how BIG and IMMENSE Salesforce is? Well...Trailhead is a "Salesforce Tutorial" for wanna be developers, wanna be administrators, wanna be users, wanna be partners, wanna be Salesforce awesome people: earn badges to show your talent and learn having nothing but fun!
You can start here following the suggested trails or you can even build your own trail with the set modules you love the most.

And what if you want to meet people on real life?


Find the Salesforce DUG (Developer User Group) near you and if you are too far you can even create your own city's official one!

And last but not least, you can be part of the DreamForce, the MOST. AMAZING. CONFERENCE. EVER. ... nothing to add more!

Imagine hundreds of thousands people all over the world that meet in San Francisco to share, learn, have fun, get some (ehm...a lot of) swag, chill out in a beatiful city.

Believe me: after DreamForce your life will never be the same!


I hope I succeeded to give you even a small idea of how amazing can be becoming a Salesforce Developer.

Everyone can build his own path to master the platform and you can start this very day for free joining thousands of people all over the world!

To increase your chances to be succesfull check this awesome ebook: Salesforce Developer Career eBook.

Believe me, you won't regret!
















Monday, September 12, 2016

[Salesforce] The Sobject Crusade: AssetTag

Source: AssetTag

This object is used to track tagging on the Asset Object.

Go to the AccountTag object for more info about how to setup tagging and see how to setup tagging on the Asset layouts:


You can select all the object layouts in which you want to use tagging.

Now you can tag your Asset object:


You can create and edit tags:


You can also have, upon feature activation, public tags, as described in the AccountTag page.

Let's query the AssetTag object:

select id, Type, Name From AssetTag

[Salesforce] The Sobject Crusade: AssetShare

Source: AssetShare

This object allow a user that has access to the record to share the Asset object directly to a User or a Group.

To create such object you have to change the Asset Sharing Settings to at least "Public Read Only" by clicking on Setp > Security Controls > Sharing Settings:


Now the Sharing button will compare on the Asset page layout (if you don't see it, add it with the layout editor):


This page shows all the users, groups, roles and territories that have access to the record.

Let's manually add a new manual share:


And this is the result (added a group and a user):


The Expand List shows the details of the users to whom the Asset is shared:


The SOQL to query the objects:

Select Id, Asset.Name, RowCause, UserOrGroup.Id, UserOrGroup.Name, UserOrGroup.Type, AssetAccessLevel from AssetShare