Salesforce Trailhead: The fun way to learn salesforce

Are you new to salesforce? Or maybe you have only worked on one area and want to learn about another?

I started on developer side of salesforce. Recently, I figured that if I know about others areas (admin, App Cloud etc) then it will make it so much easier to work on developer side. But I had the same questions as above. Where do I start?

Then I found salesforce trailhead and absolutely love it. It’s not just the content but the way it has been arranged. It took me from beginner admin to intermediate admin and other areas. After I had been through those modules, I wanted to put it all together but couldn’t figure out what I could build.

Lo and behold, trailhead has projects. These are simple enough but still allow me to combine various features that I learned.

My goal now? Go through ALL modules and projects on trailhead to get, at least, basic understanding of all salesforce features. Let the journey start……..

Apex: Find Object Type from Record ID Prefix

I get to work on objects in various orgs. It’s not easy (if at all possible) to remember entity type by just looking at Record ID Prefix. salesforce.com provides a Standard Record ID Prefix Decoder list. This still means you need to have this page handy to find those objects. Of course this list also cannot help with custom objects.

In my pursuit to find an answer, I came across piece of code that was answer to this exact problem. The answer uses iteration on metadata through Schema.getGlobalDescribe(). As it loops through all sObjects in the map, it will continue to check for prefix that we need to find. Once there, it will return the object name. By no means this is an optimized solution as it goes through loop of all sObjects till it can find the object. But this is better than having to go through other ways to find same information. Of course, if you come across an easier way then please share.

Now we can easily use this in developer console to check object name whenever we want. Of course you can take it a step further and create a visualforce page, add a search box and make it available to all developers in your org so they can easily use it (if needed).

Oh wait, we have written the class, we have tested it but we are missing an important step. Remember? Yes, “Code Coverage”. That’s an important point that we shouldn’t miss. This is important not just to be able deploy the code but it’s good development practice to make sure we test our code. Following salesforce page provides information on testing best practices.

So, I have written very basic test class to cover the code written above. You can add more functionality to your class and then expand on these basic tests.

That’s that and now we can easily figure out object name from Record ID prefix.

Please share your thoughts, questions, concerns or constructive criticism.

 

PHP My SVN Manager

I have often used SVN as Source Code versioning. Its quite a manual process to create new users, groups or repositories. Not time consuming but very manul task. This prompted me to create a PHP application which I could use to do this easily without having to logon to SVN server. This proved to be quite useful as we work on projects as team. So, now every developer can do this on their without having to send this request to me. See, real easy. Any ways, you can grab this code from following links.

Code at phpclasses.org

Code at code.google.com

 

PHP File Management Script

This class is a manager of server side files and directories.

It can perform several operations on files and directories on the server side like creating and removing directories, creating, updating and deleting files from directories, retrieving the list of files in a diretory recursively, generating a files listing in a HTML page, etc..

The class can also create htaccess and htpasswd files to restrict the Web access to a given directory to a given user with a password.

Code at phpclasses.org

 

Code at code.google.com

Optimize Your Website’s Speed

While working on a website, I noticed that website was not loading as fast as I would like it to. This prompted me to research more on it and find ways to optimize website’s performance. During this research, I came across many useful resources and tools which were very helpful. Following are some of the resources and tools that I’d like to share:

1. Use caching

Most, if not all, websites use databases to store content. This provides unique opportunity to use caching. Caching turns dynamic content into static content so that database is not queried every time a page loaded. These static copies are refreshed in a timely manner or when there is new content. This also alleviates load on web and database servers. For example, Drupal has a core module to not only enable caching but also compressing CSS and JS files (which we will discuss momentarily).

2. Compress JS and CSS

Compressing JS and CSS files is a great way to reduce web page size. CSS size, that I was working on, was reduced from 413KB to 16KB and JS size was reduced from 65K to 16KB; which also included combining all CSS and JS code in two files. There are many tools which can be used to compress CSS and JS. Two of those websites for compressing CSS and JS are http://www.csscompressor.com and http://jscompress.com.

3. Use external JS and CSS

Browsers tend cache resources like JS and CSS while loading a site. If we use CSS and JS files which are hosted on an external site used by many sites then browsers will only need to cache it for one site and re-use cached files for other sites. This technique is getting to be widely used throughout the internet for the benefit it provides. A word of caution, only use content from a trusted source because if it goes offline then it will affect your site even if your site is working as expected.

4. Use Ajax wherever possible

If your website provides content that can be loaded after page has completed loading then try to use Ajax. This can be used in cases like adding content dynamically when page end is reached (similar to Facebook).

5. CSS Sprites

CSS sprite is the method of combining multiple imagse into one image and then using CSS and background positioning these images can be displayed where needed. Using this method, browser will only need to load one image rather than multiple images and then re-use that image for other parts of the site. A good working example of this can be found at http://www.alistapart.com/articles/sprites.

6. Image format

Selecting proper image format when needed can have hue impact on website performance. One of those situations is using jpeg format for photographc images rather than gif format which is suited for text images.

7. Tools for testing speed

There are many online tools that you can (and should) use to test loading time of your website. These tools can point various resources (images, js or css) which ae dding to load time. Use these results wisely and work on a method to reduce load time of those resources. Some of these tools are http://loadimpact.com, http://tools.pingdom.com, http://www.webpagetest.org and http://gtmetrix.com.

Other than above mentioned tips, there are many ways for you to optimize your pages such as sending compressed pages using PHP (http://php.net/manual/en/function.ob-gzhandler.php). As technology evolves, new methods of optimization will be invented. So, keep an eye open for those advancements. I will do my best to research any new techniques and share with you all.

Online Courses

Coursera.com is a great website which provides many courses online for free. These are full fledged courses, generally, provided by professors or professionals in those fields.

The learning tool itself is very clean. It follows a class like structure where you have videos with a theory lesson from instructor followed by a quiz somewhere in that video and an assignment for that week’s lessons.

Drupal 7: Custom Module – Part 1

When I first started using Drupal, it was simple matter of installing and using it. Then came the task of learning how to theme. But there came a point where required functionality needed to be coded in Drupal rather than just being able to use the GUI interface. One requirement, that started my path towards learning on creating Drupal modules, was custom front-end page and serving ajax pages. I found creating those pages with a custom module easier than some other ideas. But before being able to create a custom page (which wil be discussed in later tutorial) I needed to create a custom module where I could code custom page module. This tutorial will go through steps on how to create a custom module.

A quick note, I will be going through just the basics steps on how to add module. But wherever apppicable, I will be providing links where you can get detailed information. So, think of this tutorial as well explained reference document with information on each resource and not just the reference.

[b]Requirements[/b]: Drupal 7

To start with, we will assume that the name of this module will bemymodule. So, create a folder called mymodule in sites/all/modules folder. We need at least 2 files for a module to work. You can add as many other files as you need to extend your module but these are only 2 required files for a module to work.

First file is to module information like name, description, version etc. This will be used by Drupal to determine what name, version etc. to show while viewing module list. We will now create [i]mymodule.info[/i] file in mymodule folder. This file will contain following information:

[code]
name = My Custom Module
description = “Custom module to add custom functionality”
version = 7.x-1.x-dev
core = 7.x
project = rattanpal
[/code]

Most of this file is self-explanatory. Every module has a name, description, version and core. More information on these options can be found at http://drupal.org/node/542202. Next and last required file for adding a custom module is [i]mymodule.module[/i] file. This file controls options for module access, custom menu entries, module settings etc. Following is the code that we will put in our myodule.module file; which will be explained shortly.

[code type=”php”]
‘. t(“Displays Help for MyModule”) .’

‘;
break;
}
}
?>
[/code]

[i]mymodule_help[/i] is Hook to implement Help for your module. You will eventually want to enter more information for users to help them how to use your module. This is explained in detail at http://drupal.org/node/1095546

If you were osave these changed and go to admin/modules at this moment, you will see your module listed in list of modules. At this point, you should be able to enable/install your custom module.

We will continue with this in another tutorial where we will use this module to add a custom page. We can use that page to deliever any type of content (for example, ajax to server json content or a custom front page). We will also discuss how to use permissions to secure that page, if needed.

EDIT: Part 2 of this tutorial is at Drupal 7: Custom Module – Part 2.