Thursday, May 17, 2012

Force.com Summer'12 Features

There are some Awesome features coming up in Summer'12 release. This is one release for which every force.com developer is waiting. Some of the interesting features listed below. I can't wait to lay my hands on these and test them....Phew!

Apex Describe Support for Field Sets
Visualforce dynamic bindings have supported field sets for some time. In Summer ’12, Apex provides describe support
for field sets, which makes it possible to dynamically generate the SOQL necessary to load all fields in a field set. This
makes field sets easier to use in Visualforce pages that use custom controllers.
This sample uses Schema.FieldSet and Schema.FieldSetMember methods to dynamically get all the fields in the
Dimensions field set for the Merchandise custom object. The list of fields is then used to construct a SOQL query that
ensures those fields are available for display. The Visualforce page uses this class as its controller.

Single View State—Generally Available
The Single View State optimization introduced as a pilot feature in Spring ’12 is generally available in Summer ’12.
Single View State will be activated on existing organizations within 24 hours of deployment of Summer ’12 on your
Salesforce instance.

JavaScript Remoting Enhancements
We’ve enhanced JavaScript remoting in several ways.
To make it easier to work with namespaces, especially for pages that make remoting calls to methods provided in packages,
you can use the $RemoteAction global to automatically resolve the correct namespace, if any, for your remote action.
To use this facility, you must explicitly invoke JavaScript remoting. The pattern for doing this is:
Visualforce.remoting.Manager.invokeAction(
'fully_qualified_remote_action',
invocation_parameters
);

There are lot of other features like

JSON Parser
New Types 
Sorting Support for Non-Primitive Data Types in Lists
Knowledge Management Publishing Service Class
Describe Support for Field Sets
New Interfaces and Methods for Running Apex on Package Install/Upgrade and Uninstall
Allow Reparenting Option in Master-Detail Relationship Definitions
New Lookup Relationship Options etc..

You can get the release notes from here Salesforce Summer'12 Release Notes


Wednesday, May 16, 2012

Dynamic Visualforce Components Explained


Some or the other time you might have faced a challenge of dynamically generating input fields. Most of the time we sticked to dynamic HTML and embed that in our VF page to fulfil our needs.

But now, Salesforce has introduced the new Dynamic visualforce components which means you no longer will be dependent on dynamic HTML for most of your needs.

Here is a sample which shows you how to generate a dynamic input form for Account object.

Page
<apex:page standardController="Account" extensions="DynamicInputForm">
<!-- Create section header dynamically -->
<apex:dynamicComponent componentValue="{!SH}"/>
<apex:form >
<!-- Create dynamic input form for account object -->
<apex:dynamicComponent componentValue="{!ActForm}"/>
</apex:form>
</apex:page>

Class
public with sharing class DynamicInputForm
{
    public DynamicInputForm(Apexpages.standardController ctlr)
    {
        //constructor code goes here
    }

  
    //Create a page block dynamically
    public Component.Apex.PageBlock getActForm()
    {
        Component.Apex.PageBlock pb = new Component.Apex.PageBlock();
      
        //creating an input field dynamically
        Component.Apex.InputField name = new Component.Apex.InputField();
        name.expressions.value = '{!Account.Name}';
        name.id = 'name';
        Component.Apex.OutputLabel label = new Component.Apex.OutputLabel();
        label.value = 'Name';
        label.for = 'name';
        //Use the above block to create other input fields
      
        Component.Apex.CommandButton save = new Component.Apex.CommandButton();
        save.value = 'Save';
        save.expressions.action = '{!Save}';


        pb.childComponents.add(label);
        pb.childComponents.add(name);
        pb.childComponents.add(save);
        return pb;
    }

  
    //create section header dynamically
    public Component.Apex.SectionHeader getSH()
    {
        Component.Apex.SectionHeader sh = new Component.Apex.SectionHeader();
        sh.title = 'Create Account';
        return sh;
    }
}
Updated Visualforce developer guide covers this topic.

Monday, January 16, 2012

Force.com Spring'12 Release Feature Set


Apex REST Updates

We’ve streamlined Apex REST and made it even easier to develop your custom endpoint. The following changes have been made to Apex REST API:
  • Apex REST automatically provides the REST request and response in your Apex REST methods via a static RestContext object. You no longer need to declare a RestRequest or RestResponse parameter in your method.
  • User-defined types are now allowed as Apex REST parameter types.
  • Apex REST methods are now supported in managed and unmanaged packages.
  • The order of elements in the JSON or XML response data no longer has to match the Apex REST method parameter order.

Concurrent Apex Jobs

Salesforce has increased the limit for the total number of Apex classes that you can schedule concurrently to 25 (the previous limit was 10). With this higher limit, you can now schedule more Apex jobs for concurrent execution.

ContentDocument Triggers

You can now associate Apex triggers with the ContentDocument object. You can create Apex triggers for the ContentDocument object only through the Metadata API. Alternatively, you can create the triggers using the Force.com IDE or the Force.com Migration Tool, both of which make use of the Metadata API.

OFFSET added to SOQL (Pilot)
We’re adding a new clause to SOQL which will allow your app to view records after a certain offset. Use OFFSET to specify the starting row offset into the result set returned by your query.
Using OFFSET is helpful for paging into large result sets, in scenarios where you need to quickly jump to a particular subset of the entire results. For example, the following SOQL query returns a result set that skips the first 100 rows of the full query results:
SELECT Name FROM Merchandise__c WHERE Price__c > 5.0 ORDER BY Name LIMIT 50 OFFSET 100
The resulting set of records would still be limited by 50, but would begin with the 101st record in the result set.
This feature is in Developer Preview. Please contact Salesforce.com to enable it.