November 19, 2011

XCollections - Use Custom Apex Classes in Map & Set.

Apex currently doesn’t supports User defined Classes/Types(UDT) to be used in Map and Set classes. This is a very hurting limitation in some scenarios.

To overcome this limitation, “XCollections” Apex API project was started few weeks back as an independent project on github. This API as of now has two major classes called XMap and XSet that allows use of UDTs.

Regarding XCollections, I had a discussion with two very respected and well known guys in force.com community( brief intros added below, to help my new force.com peers)

  • Richard Vanhook(Force.com MVP & Tech. Sol Architect @ Salesforce.com)
  •  Joel Dietz(Force.com MVP & Tech Architect @T’quilla Ltd) about XCollections.

We decided that better place for this API is in a sub repository named “collections” under very popular apex-commons framework. So going forward XCollections will be available as “collections” in apex-commons.

Today, I wrapped up long time pending tasks like

  • Code clean up
  • Readme.md in github flavored markdown.
  • Test cases
  • And final push and pull requests for apex-commons :) (waiting for the merge)

You can find complete details about this project and how to use the API here : https://github.com/abhinavguptas/collections

References

Your views and feedback !

Always  appreciate & love to discuss your feedback and views, so looking forward to those :)

November 17, 2011

Force.com ESAPI v0.5 & death of Apex-CRUD-FLS-Validator API.

“Apex-CRUD-FLS-Validator” was an open source project I started few days back on github. Motive of this project was to add some handy apis that were missing previously in Force.com ESAPI v0.4. Those missing APIs on a high level were

  • operation to assert() and throw exception if CRUD/FLS is violated. We found it better to crash the page for security error like Salesforce does, so that admin can give the required access. Showing blank values or hiding items was a challenge to handle in complex screens.
  • operation to check if CRUD/FLS is available on a given Sobject/Fields. This information is used later to show/hide a few links/buttons/sections.
  • ability to cache the field describe call and reuse it across. This is important, as we are already caching describe information as part of other requirement, and don’t want to spend more describe calls for security enforcement on same sobject/fields.

 

Apex-CRUD-FLS-Validator APIs merged with Force.com ESAPI

To merge these Apex-CRUD-FLS-Validator APIs with Force.com ESAPI, I had a discussion with Yoel Gluck. Yoel maintains the Google Code project for ESAPI and is Lead Product Security Engineer at Salesforce. In our discussions about adding these new APIs to the Force.com ESAPI project we figured out plan to merge the APIs.

Neal Harris(Associate Product Security Engineer at Salesforce.com) is the man who finally made this API merge happen, he introduced following new APIs to release out  v0.5 of Force.com ESAPI.

  • Added new functions isAuthorizedToView, isAuthorizedToCreate, isAuthorizedToUpdate, and isAuthorizedToDelete.
  • Added new functions getViewableFields, getUpdateableFields, and getCreatableFields accepting an sObjectType as input.
  • Added a describe info cache. Now all the field desc information is cached
  • Apart from caching the desc information, we are giving a pluggable desc info cache support. This will help those who are already caching desc information in their own apex data structures, those same can be easily reused with ESAPI now, with small piece of code change.

 

Apex-CRUD-FLS-Validator is dead now

Apex-CRUD-FLS-Validator project is no more on github now, any related documentation on my blog etc is also deleted to avoid any ambiguity.

Coming up next !

Coming up next is a couple of blog posts and wiki page updates about the new APIs, code samples and tricks to make most out of them.

November 12, 2011

Self Explanatory naming convention for your Apex Classes

I am following an apex class naming convention in a couple of projects for a while and its turning up well and big timesaver for me, so thought of sharing with you all.

Why a special naming convention ?

You must be thinking, “why a special naming convention ?“ This is required because apex classes doesn’t support nested namespaces or packages(java) to organize code in a clean way. So mostly the “classes” area for an org with reasonable code ends up in a mess. Its hard to tell which class is of what use most of the times. A good example with few classes would be

  • ContactDuplicateCheck < Used in contact dedupe trigger
  • OpportunityAmountValidator < Used to validate opportunity amount in a trigger on opporunity
  • OppLoadController < Visualforce controller
  • AccountLoader < Visualforce extension used to load accounts
  • ContactMergeExtension < Contact merge based on custom logic, an extension class for a VF page.
  • ContactService < WebService based on Apex
  • BulkRecordCleaner < Batch job that cleans the records.
  • NightlyAccountSync < Nightly scheduled job that syncs the system accounts.

It would be hard to tell the use/purpose of above classes, without the desc I added. But this situation is more panic, when many developers are working on the same code base.

Better Naming convention !

 

Approach 1 : Prefixing class names

Apex class names can be prefixed based on the functionality, feature etc

“{prefix}_classname.cls”

Approach 2 : Suffixing class names

UPDATE : 16/Nov/2011 : Based on discussion in post comments with @jpseabury & @RalphCallaway, another approach was highlighted to do the suffixing in similar way. The plus of doing this is “Classes would be correctly sortable in “Apex Classes” section in setup area.” For more details on this, please check the respective comments in this post.

“classname_{suffix}.cls”

Suggested prefixes/suffixes based on scenario

  • page : For all controller and extension classes connected to visualforce pages. Ex. names would be page_OppLoadController, page_AccountLoader.
  • trgr : Any class used by triggers. Example class names would trgr_AccountTriggerHandler, trgr_ContactDuplicateCheck, trgr_OpportunityAmountValidator
  • hlpr : For all the classes, that are having reusable code for helper or utility functions. For ex. any code that is common and reused between triggers and page controllers.
  • btch : Classes for batch jobs.
  • schd : Classes for scheduled jobs.
  • glbl : All global classes.
  • ws : All classes declaring web services in them.
  • test : For all test classes.

You can easily imagine, how easy would be the life on a reasonably big project with many apex classes.

This is how the above class list will look after prefixing.

  • trgr_ContactDuplicateCheck
  • trgr_OpportunityAmountValidator
  • page_OppLoadController
  • page_AccountLoader
  • page_ContactMergeExtension
  • ws_ContactService
  • btch_BulkRecordCleaner
  • schd_NightlyAccountSync

Isn’t it cleaner and self explanatory.

Your thoughts and views ?

Looking forward to those …

November 8, 2011

Rich Visualforce Editor, major feature update live !

 

IMPORTANT: Author of this plugin might not get alerted for any comments made here on this blog’s comments section. I request you all to directly raise issue on the github repository for this product here : https://github.com/ajayhada/Rich-VisualForce-Editor/issues

For those who don’t know about Rich Visualforce Editor, its discussed in my previous blog post. On a high level it gives content assist support in visualforce.

New updates !!!

@AjayHada added a couple of new features to Rich Visualforce Editor, like :

  • Context sensitive help for visualforce tags, i.e. select the tag name and press “CTRL + 1”
  • Toolbar icons to quickly launch visualforce and apex developer guide right inside eclipse.
  • Contextual icons in content assist box for tags and attributes.
  • Update site support. Now updating the plugin is super easy.

Further details below about each update :

Context sensitive help for Visualforce tags !

Now if you need to know more about a visualforce tag you are currently coding around. Just select the tag name after “apex:”, as show below

rich visualforce editor context sensitive help by keyboard shortkey

rich visualforce editor help page opened

TODO : Please note, we are working on an enhancement that will open context sensitive help on a tag without selecting the tag name. It will be out soon in a week time.

Toolbar icons for Visualforce & apex developer guide

Two new toolbar icons are added to quickly launch Apex and Visualforce developer guide right inside eclipse.

toolbar icons to launch apex & visualforce developer guides in eclipse

Contextual icons in content assist box for tags and attributes.

Content assist box is beautified now to support different icons for tags and attributes as shown below.

tag icon in content assistattribute icon in content assist

Update site support

Now less of manual intervention is required in updating the rich visualforce editor. It supports Update site from this version. To update, please follow these steps

  1. Goto “About Eclipse” dialog.  To get this dialog, Mac users “Eclipse > About Eclipse”, Windows/Linux users, “help > about eclipse”.About eclipse dialog
  2. Hit the “Installation details” button.
  3. Hit Update button in next dialog as indicated below. Please agree and complete the next screens on the update flow  : Dialog after hitting the update button

 

Roadmap

We are working in couple of more features as mentioned in TODO section of my previous post.

Feedback & Views

Looking forward to those !

November 2, 2011

Rich Visualforce Editor that finally supports Content Assist !

IMPORTANT: Author of this plugin might not get alerted for any comments made here on this blog’s comments section. I request you all to directly raise issue on the github repository for this product here : https://github.com/ajayhada/Rich-VisualForce-Editor/issues

We all miss content assist support in Force.com IDE Visualforce editor. My previous attempt of using eclipse code templates was a patch to fill this gap. Good news now is, my colleague @AjayHada is creating a Visualforce editor, that will give decent code assistance support on typical “CTRL + SPACE” hit.

Meet @AjayHada !

Before we go any further, let me introduce you all with @AjayHada. He is a J2EE champ with a decade of experience in developing applications ranging from Supply chain management, ERP and Social Event management.

AjayHada’s experiences with Force.com IDE :-/

Ajay recently started learning and developing on Force.com platform. After a few days of flying in clouds, his major point of frustration was Force.com IDE, because of its well known limited capabilities. Being a Java guy by heart, he decided to write an Eclipse plugin to fill this long void, and he started an open source project for visualforce editor. After a few hours of research and RnD he was able to come up with an alpha version of this editor.

This editor is available on github here : https://github.com/ajayhada/Rich-VisualForce-Editor

Rich Visualforce Editor Plugin for Force.com IDE

This editor in its infant stage is supporting content assist for most commonly used visualforce tags.

How to launch ?

launching rich visualforce editor

  • Right click on any Visualforce page, to launch the popup menu.
  • Select “Open With” menu item.
  • In the sub menu select “Rich Visualforce Editor”.

 

 

Content assist in action !

control space with visualforce editor tags

CTRL + SPACE in action for tags

tag specific attributes in visualforce editor

CTRL + SPACE assistance for tag specific attributes

 

Liked it, How to install ?

You can download this zip “rich.visual.force.editor.plugin.zip” from here. After download extract the zip and copy “VFEdit_xxxxx.jar” to “eclipse install folder/plugins”. Restart eclipse to reflect the changes.

Rich Visualforce Editor Roadmap & TODOs

Following are the features planned in next release. You are more than welcome, to fork and contribute to any of these.

  • HTML5 tag support will be added to future versions
  • Only applicable tags will be visible inside tags like apex:param will only be visible for applicable parent tags
  • Display validation errors for apex and html tags
  • Used attributes will be removed from the suggestion box.
  • Suggestion box will also show some mark to show that tag is related to APEX, or HTML4, or HTML5
  • Proper Tag, Attribute, Text, Comment color scheme
  • Context sensitive help within IDE on pressing a hot key for visualforce tags.
  • Support for “plugin update site” for all known pros.
  • Support for dynamic update of tags and attributes, as per new Salesforce releases.

 

Help required from Force.com IDE team !

This plugin can be more awesome, if they can give us XSD/DTD for visualforce tags. This will help a lot in developing this editor in lesser time.

Your views and feedback !

Looking forward to those