James Derulo's

Portfolio

Mavensmate is one of the most widely adopted force.com plugin and it is currently offered for Sublime Text and Atom (Open Github Editor). For some reason, I see many folks confused and struggling to configure that Mac machine successfully, which is why I am writing this blog post explain step by step instructions to configure Maven on your machine.


Sublime Installation  : 


Step 1 : Go to Sublime Text and open package control (see how to install package control) by pressing (⌘ + Shift + P) and type Mavensmate. 






Step 2 : After installing package, now download Mavensmate standalone application for your machine from here (get latest version), unzip and install it in Application Folder.



Step 3: Launch application, go to Settings set mm_workspace. In my case, I created a folder in  Documents/Sublime so my path will become /Users/harshitp/Documents/Sublime

Your mm_workspace will become (replace your username)

["/Users/harshitp/Documents/Sublime"]




Step 4 : Pass on your credentials, if your path is correct, you should see absolute path in the drop down menu as shown below.



Step 5 :  Start using Sublime Text



Atom Installation  : (Multiple Workspace)

Steps are same, just to keep manage project nicely, create another folder (again depends on your need) in the Documents folder naming 'Atom' so my directory structure looks like this Documents/Atom 

Step 1 : Configure mm_workspace

For Atom directory my absolute directory path for mm_workspace  becomes /Users/harshitp/Documents/Atom


["/Users/harshitp/Documents/Sublime", "/Users/harshitp/Documents/Atom"]


Step 2 : Pass on your credentials, on successful settings you will be prompted to open both editors and option to choose workspace like this



Step 4: Sync Salesforce and started coding on Awesome Atom Editor





Promises are one of the most valuable additions in world of Javascript. Promises are the way to handle asynchronous javascript  to avoid nest callbacks.

Asynchronous pattern is more common and vital for moving to advanced web programming. But asynchronous programming is challenge to work in Javascript. To make life easier, DOJO and Jquery have introduced promises with ECMA5 support.

Traditional JavaScript callbacks work very well up to a point, but we run into problems when we’re waiting for multiple conditions to be met. Anyone who has used Node.js will be familiar with the concept of callback hell:


One pattern is a promise, which represents the result of a potentially long running and not necessarily complete operation. Instead of blocking and waiting for the long-running computation to complete, the pattern returns an object which represents the promised result.

Promise leverage a pattern which represent the result of long running and everlasting operation. Instead of blocking single threaded javascript process and waiting for ever running computation to complete, promises pattern return a object reference which represents the promised result.

At any moment in time, promises can be in one of three states: unfulfilled, resolved or rejected.

You can design a method on promised object and then add handlers for resolved and rejected states.This function returns another promise object to allow for promise-pipelining, enabling the developer to chain together async operations where the result of the first operation will get passed to the second.

Bootstrapping Promises Code 

Code snippet below initiates promised object use then to perform action on complete and handler on covering actions to be taking on success and failures.


Using a Promise states 

Promise can stay in three states : pending, resolved and rejected

Let us create a promise, see snippet below, and here since we initiated promise but it doesn't do anything, clearly our promise state becomes Pending here.

We can use then() method to handle other promised state like resolve for success and rejected for failure.

Injecting Javascript Dynamically to WebPage with Promises

While developing application and libraries in Salesforce, often we countered scenarios where we need to dynamically inject custom javascript on header of the page and might need to perform a order of load. In few of the cases, like injecting map application on the page, we need jquery, map library in a certain order and only show success when promises is loaded in an order. So I am sharing some of the code snippets.

In the snippet below, we call reject function to handle callback on failure and similarly resolve method on success.


Injecting Javascript in Google Way


Google uses smarter script to inject script on any page, here is wrapper function around it with promises


Injecting Javascript in Facebook Way


Facebook rather look for script with and Id, avoid inject duplicate script and here is wrapper function around it with promises


Loading Promises in Series


Now this is more interesting, if we have multiple libraries to load on DOM build, we can simply make minor modification of code to inject them in specific order.

Simply call method we designed about this fashion, show in snippet below



Loading Promises in Parallel


This approach will allow the process to load all in parallel instead of waiting for one return to invoke another, there are two static method available that can help you achieve that.

Promise.all and Promise.race are static methods that each take an Array of Promises as an argument, returning a new Promise. Both methods will watch the Array but with one important difference; Promise.all will resolve when all of the Promises in the Array have resolved, whereas Promise.race will resolve as soon as any one Promise in the Array has resolved.

Lets modify our first promise code a bit to accomodate this change.


Using Promise Loader in Visualforce Page

In Salesforce, here I am injecting all required static-resources can be injected by local static resource or via CDN. Here I am injecting all needful scripts, in series on a visualforce pages, before the DOM is built, which uses 'Windows.Paint()' method.


Using Pure .loadScript 

Simply Using .when()method to load script with promises


Utility Method to Loading Array of Scripts;

I improved and wrote a utility method that loops through script array inject scripts

This can be used to call multiple script in loop like this


Also, if any of the scripts fail to load, the fail handler will be called, and subsequent scripts will not be loaded


Using YepNope.js


YepNope is an asynchronous conditional resource loader that's super-fast, and allows you to load only the scripts that your users need. Scripts with the same url won't execute twice, but their callbacks fire in the correct order and also can be use


Using YepNope.js to Load CSS



Q.Js : A tool for creating and composing asynchronous promises

Q.js is neat wrapper library written to handle asynchronous promises, we have been using for couple of our projects and by far it neat and fancy library written to simplify readability, ease of code.

Using Q.Js I wrote a script snippet that uses q.js to dynamically injects script on the page, this script run on every page load.


Using jQuery to asynchronously load script, similar to promises

jQuery can also be used to load synchronously but without promises and similar methods. 


Summary

You can use any of these approach to handle asynchronous programming in Salesforce or Web project, I recommend reading HTML5 Rocks Post and Mozilla foundation post for further reading.



Announcing Weave, a coolsome project, that generates boilerplate code for creating cutting age visualforce pages and apex code patterns for Salesforce on your Sublime Text Editor. A homegrown  product of our lab experiments.

What is Weave ? 

Weave is sublime plugin, that generates the boilerplate code for both Visualforce and Apex. Since we are more focused on leverage material design experience on top of Salesforce. We designed boilerplate snippets for Material Design that generate fancy pages by typing few keywords. See all those wonderful template on 'feather' project, which become mother of Weave project

Why Weave ?

While working in  large team, you might need to bring code consistency among the team. Weave generate out box template code to bring your team productivity upto speed. I open-sourced this project to get more ideas from developer community and correct templates and simply standards of the platform across the board.

See Weave in Action

 Follow the video to have glimpse on how to install and use Weave for spinning Visualforce Code




Weave support Google Material Design 

We wrote generic template based off of Material design that can be easily generate through by typing 'vf_' and '<tab> in your machine, here are few glimpse. Note Vf_ generates all visualforce templates.


Visualforce Page with Material Design Fixed Tabs 


                       
See this page live here

Can it Weave Apex ? 

Yes, we wrote powerful templates jump start Apex code.To support industry design pattern, we wrote snippets for Trigger covering all possible event and TriggerHandler, you simply have to press type make appropriate changes and weave will fill up values for you, not shit just simplify life of developer

See Weave in action with Apex Code in the video below


How to install  ?



Salesforce announced Salesforce User Event-2016, to be held in Harrah Lake Tahoe located at South Lake Tahoe in California very similar to Midwest Dreamin. Clearly it would be fun event, specially its winter and Tahoe is awesome place to be.


What's more fun to me was produce this thrill-chill and awesomeness using Javascript/CSS and simple code-logic, if you do not understanding that just checkout a fun and fancy code I wrote to explain chill/thrill of surfing in the cloud you might get in Tahoe Dreaming.
Embedded below is the codepen snippet, but I recommend watch full page, just hover the mouse to explore




ForceSpinner is powerful jquery plugin we wrote to add interactive and engaging loaders for force.com project. We thought of writing custom components, but later extended them to be adopted for HTML project using jquery.


ForceSpinner offer wide variety of loaders for you to offer engaging user experience in simplified fashion. You need jquery to use this plugin successfully and this plugin allows you the change the colors of the loaders by simply passing color in the methods.



While working on Material Design with Salesforce, we came across situation where we have to show loaders while content loads during a transaction in Salesforce. We wrote a simplified plugin from scratch, using pure CSS3 to simplify showing loader while your content loads.


How to use ForceSpinner ?


Plugin is simple and easy to implement, you need to import CDN or download css/js and simple invoke loader by calling methods shown below

Check out similar libraries ForceGrid (Grid System for Salesforce) and ForceSniffer (Salesforce Context Library for Devices Detection).

ForceGrid is a responsive CSS grid micro framework. It is tiny, have no dependencies,it comes with fluid columns with fixed gutters, supports infinite nesting, and doesn't constrain you to any column sets or media query breakpoints. It embraces concepts of progressive enhancement and mobile first, serving one-column mobile layout to older browsers (IE 6-7-8-9-10 and new Microsoft Edge IE-11).



Why you need this for Salesforce Projects ? 


Most of the clients have not moved to Salesforce Lighting UX, so in classic model quite often you have to keep header and sidebar of Salesforce open. Adding Twitter Bootstrap/Material Design fancy framework over-ride css and mess up standard Salesforce look-feel.



So I wrote a very lightweight and simple grid system which make sure that your content is responsive. I started with writing a basic css as shown here in my last post explaining how to write a responsive grid. Then later formulated into library called ForceGrid.


How to use ForceGrid ?


Define your layout by assigning dimension like 2-by-2 or 3-by-3 for dividing the page into simple two equal or three equal halves respective and wrap responsive content in wrapper div, and ForceGrid takes care of the rest.

Dividing Page in Two Equal Halves : 


First Half

Second Half


ForceGrid with Visualforce 


Simply import css in your project or use this cdn or import from Github Project


Source Code 


To learn more go to ForceGrid Homepage or  use Github repository to fork code.


You probably should not have to find/detect device type unless you absolutely have to. In most of the cases, a good responsive design in UI can render behavior across different screen sizes.Though there are few edge cases in Salesforce development specially, where you want to redirect traffic to mobile specific page,detect device and even detect Salesforce1 Application itself.

I found an interesting discussion here, talking about multiple approaches for device sniffing, specially through javascript and css. Clearly both approaches are cool, but, while developing application oriented for salesforce1 mobile application, lightning experience, salesforce on safari/chrome in ipad and as well any other device, you still have to write script handler to detect those devices.I saw few cases very well covered by +Keir Bowden in this post here, where he explain the different context a user have to deal with, and sniff multiple cases.

Detecting with Javascript if Salesforce1


I thought of organizing all types of device detection techniques into one organized library that can detect mobile(all possible) devices and all possible salesforce context. Inspired by isMobile.js I compiled all logic a one place, which gave birth to ForceSniffer.js

 Simplified way of sniffing (User-Agent) including Salesforce

How to use ForceSniffer.js ?

Simply import forcesniffer.js in your visualforce page and call the methods as shown below to detect devices and context, you can also import forcesniffer.js as CDN from here

Check if Mobile

/* Smartphones ----------- */
//Check for all Phone
if(isMobile.phone)
{}

Check if Tablet
/* Smartphones ----------- */
//Check for all Tablet
if(isMobile.tablet)
{}

Check if Desktop
/* Smartphones ----------- */
//Check if Desktop
if(!isMobile.any)
{}

Check if Salesforce1
/* Smartphones ----------- */
//Check if Salesforce1
if(ForceUI.isSalesforce1())
{}

Check if Lightning Experience
/* Smartphones ----------- */
//Check if Lightning Experience
if(ForceUI.isLightingX())
{}

Check if Visualforce Inside Saleforce
/* Smartphones ----------- */
//Check if Visualforce Inside Saleforce
if(ForceUI.isVisualforceInside_Salesforce1())
{}

Check if Visualforce inside Salesforce1 Classic
/* Smartphones ----------- */
//Check if Visualforce Inside Saleforce
if(ForceUI.isVisualforceInside_SalesforceClassic())
{}

Below the live example of using ForceSniffer on a visualforce Page

Previous PostOlder Posts Home