Apex FlexQueue muscles Apex Batch Processing

Batch Apex is salvation for developers. It allows you to serve large number of dataset(upto 50 million). I always employ Batch Apex to build complex, long-running processes on the Force.com platform. Although I can process over millions of records with Batch Apex, it has some platform limits. There can be only five active or queued jobs.

Why is this limit like this in the first place?

Salesforce always put limit in the first place because of its multi-tenant architecture. All asynchronous jobs are end up with the message queue. These message queues are having some sort of concurrency control mechanism just to make sure that one org does not monopolize.

A batch process can iterate over millions of records, and can take hours to run.  If your org had five of these long-running batch jobs in flight, anything you enqueued after that would be busy-waiting, due to concurrency controller. As such, the limit was created to prevent you from adding a sixth job while the five long-running jobs were consuming resources.

FlexQueue muscles Apex Batch Processing

In this Summer’14 release salesforce introduce new feature called “FlexQueue“. FlexQueue allows you to submit batch jobs beyond the limit of five queued or active jobs and give access to those jobs which are waiting to run. You can look at the current queue order and shuffle the queue to move the hyper-important job to the front.

shuffle queue

How it works?

In the current architecture, your batch job is serialized and included directly in the MQ message. For FlexQueue, your job is serialized to a “holding pen”, and a “token” is enqueued in the message queue. While tokens are in the queue waiting for resources, the holding jobs can be reordered. When a token reaches the front for processing, it will take the first job in the holding area.

To submit a batch job, call Database.executeBatch. The resulting outcome of Database.executeBatch depends on whether your organization has reached the five queued or active batch job limit.

  • If system resources are available for processing jobs, the batch job is queued for execution and its status is Queued.
  • If no system resources are available, the batch job is placed in the Apex flex queue and its status is Holding.
  • If the Apex flex queue has the maximum number(100) of jobs, this method returns an error and doesn’t place the job in the queue.

Currently in Summer’14 this feature is in pilot, but in Winter’15 it will generally available. (if everything goes well in pilot)

FlexQueue is like Cherry on the Cake. Salesforce not only allow me to process millions of data but also allows to manage my own org’s order-of-operations. I am just impress with this new feature. Yes, actually it muscles batch processing. 🙂

Advertisements

Salesforce | Summer’14 Release features

Salesforce’s Summer’14 release came up with lots of leverages for developers as well as for ISVs.

Here I have highlighted few of them :

  1. Visualforce Remote Objects
    JavaScript remoting is very powerful and popular method building web app with Visualforce. This will give you helping hand to perform DML on sObjects directly from JavaScript.
  2. PageReference URIs Support Anchors
    You can construct PageReference objects with URIs that include anchors or fragment identifiers, that is, an identifier following a hash symbol (#).
    For example :
    PageReference pageRef = new PageReference(‘/apex/MyPage#mainSection’);
  3. New methods have been added to String class
    1. escapeJava
      Returns the string whose characters are escaped by Java rules.
    2. escapeUnicode
      Returns the string whose Unicode characters are escaped to a Unicode escape sequence.
    3. unescapeJava
      Returns the string whose Java literals are unescaped.
    4. unescapeUnicode
      Returns the string whose escaped Unicode characters are unescaped.
  4. Attach file upto 25 MB for objects, previously it was 5 MB.
  5. Limits for all apex describe calls have been removed for all API version.no limits
  6. Script statements limit methods have been removed but available in deprecated in API version.
  7. Apex Flex Queue – Pilot
    Flex Queue will help you to submit batch jobs beyond the limit of 5 queued or active jobs
  8. Now you can run future method with higher limits (but currently its in pilot)
    For example,
    @future(limits=’2xHeap’), @future(limits=’2xSOQL’) etc.
  9. Lots of changes and new features have been added to Chatter in Apex, for that you can visit this link.
  10. The good news for developers is that the API request in developer edition is raised to 15000, previously it was 5000.
  11. Salesforce has included some imp features for ISV partners.
    1. Deleting managed package components
      I must say this is the best feature for every ISV partner. Some times some components get added into the manage package which may lead to some unwanted limitation in your package. If something similar happens with you then this feature will defiantly like lifeline for you.
      This feature help you to remove unwanted components from your manage package. It includes following components while updating a previously released managed package.

      1. Custom Buttons and Links
      2. Custom Fields
      3. Custom Objects
      4. Custom Tabs
      5. Field Sets
      6. Record Types
      7. Validation Rules
    2. Usage Metrics – Pilot
      This feature is currently available through a pilot program. To enable this feature you need to contact Salesforce.com.
      This feature will allow you to collect detailed usage metrics from each Organisation in which your managed package is installed. This will help you to design your Road Map for next version of app release.