When Salesforce is life!

Tag: Github

[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/.

[Github / Maven] Maven repository using GitHub

This simple post is a reminder on how to create a Maven2 repository and use it with Maven in a “pom.xml” file or in Java Play!. The first step is to create a GitHub Repository (it will be named “maven2”).Then reproduce the folder structure of a Maven Repository, as I did in my “Maven2” repo (https://github.com/enreeco/maven2).For instance, given this artifact (jar):

<groupId>com.rubenlaguna</groupId>
  <artifactId>evernote-api</artifactId>
  <name>Official Evernote API</name>
  <version>1.22</version>

Create these folders:

./com
     ./com/rubenlaguna
     ./com/rubenlaguna/evernote-api
     ./com/rubenlaguna/evernote-api/1.22
     ./com/rubenlaguna/evernote-api/1.22/evernote-api-1.22.jar
     ./com/rubenlaguna/evernote-api/1.22/evernote-api-1.22.pom

Now you have a pubblicly accessible Maven2 repository at https://github.com/[username]/[repoName]/raw/master/ (in my case https://github.com/enreeco/maven2/raw/master/).To consume it in your projects, just add this lines in the “pom.xml” file of your project:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" 
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>com.echoservice</groupId>
    <version>1.0-SNAPSHOT</version>
    <artifactId>echoservlet</artifactId>
    <repositories>
    <repository>
      <id>myRepository</id>
      <url>https://github.com/enreeco/maven2/raw/master/</url>
    </repository>
    </repositories>
    <dependencies>
 . . .
 </depencencies>
 . . .
</project>

To integrate the maven repo in a Java Play! project (necessary if you’re messing with Heroku), take the “/prject/Build.scala” file and add those lines:

import sbt._
import Keys._
import PlayProject._

object ApplicationBuild extends Build {

    val appName         = "evernote-integration"
    val appVersion      = "0.1"

    val appDependencies = Seq(
      "com.rubenlaguna" % "evernote-api" % "1.22", //Evernote Thrift Library
      "com.rubenlaguna" % "libthrift" % "1.0-SNAPSHOT",//Thrift core library
      "postgresql" % "postgresql" % "9.1-901.jdbc4", //Postgres
      "org.apache.httpcomponents" % "fluent-hc" % "4.2.1" //Apache HTTP client
    )

    val main = PlayProject(appName, appVersion, appDependencies, mainLang = JAVA).settings(
     resolvers+= "personal maven repo" at "https://github.com/enreeco/maven2/raw/master/"
    )

}

Maven will search for the selected jars in the default locations, but when it’s not finding anything it will search for your personal resolvers.

Powered by WordPress & Theme by Anders Norén