Sunday 13 May 2012

Feed Tracking more than 20 fields in an Object

Please refer to my previous posts regarding Feed Tracking and Chatter Approvals for better understanding.

We all know that, Feed Tracking is greatly used to expose the changes of a field in an Object via Chatter Posts on successful save of the record.

Whenever a field change occurs, then Chatter Posts will be added automatically on behalf of the User consisting of,

1. Field Name

2. Old Value of the Field

3. Newly updated value of the Field

Feed Tracking can be enabled for only 20 fields in an object. This posts illustrates a simple work around using Trigger to overcome the 20 field limit.
// Triggered whenever a Opportunity is Updated and Saved
trigger ChatterUpdatesOppty on Opportunity (after update) 
{
  List<feeditem> fi=new List<feeditem>();
  List<entitysubscription> es=new List<entitysubscription>();
  Boolean flag=false;
  for (Opportunity o : trigger.new)
  {
    if(o.DeliveryInstallationStatus__c!=
              System.Trigger.oldMap.get(o.Id).DeliveryInstallationStatus__c)
    {           
      FeedItem f=new FeedItem();
      f.ParentId=o.Id;
      f.Title=o.Name;
      f.Type='TextPost';             
      f.Body='changed Delivery/Installation Status from '+
              System.Trigger.oldMap.get(o.Id).DeliveryInstallationStatus__c+
              ' to '+o.DeliveryInstallationStatus__c;                            
      f.CreatedById=o.LastModifiedById;
      fi.add(f);            
      // CHECKING WHETHER USER IS ALREADY FOLLOWING THE RECORD OR NOT            
      for(EntitySubscription eee:[Select Id, ParentId, SubscriberId, 
          CreatedById, CreatedDate, IsDeleted FROM EntitySubscription where ParentId like '006%'])
      {
        if( eee.ParentId==o.Id && flag==false)
        {
          //YES, USER IS FOLLOWING THE RECORD
          flag=true;
        }
      }                      
      if(flag==false)
      {    
        //MAKING USER TO FOLLOW THE RECORD
        EntitySubscription hi=new EntitySubscription();
        es.add(new EntitySubscription(ParentId=o.Id,
               SubscriberId=o.LastModifiedById));                
      }
    }
  }    
  insert fi;                    
  insert es;
}
This trigger additionally incorporate a method to add the User as a Follower of the record automatically making him/her to receive updates when someone added a comment to the Feed. Hence using this Trigger, any number of fields can be Feed Tracked and can be considered as an alternative to Standard Salesforce Feed Tracking.

Friday 11 May 2012

Chatter Approvals - A Collaborative Method of Approval Process....

We all know that, an approval process is an automated process in an organization used to approve records in Salesforce. An approval process specifies the steps necessary for a record to be approved and who must approve it at each step. Approval process also specifies the actions to take when a record is approved, rejected, recalled, or first submitted for approval.

This post demonstrates chatter way of Approving Records...Sounds good!!! isn't it??

Definitely, this method would make processes much faster when combined with the well known and familiar Approval Process.

Let us assume a scenario that, every newly created/updated Contract record need to be approved by me by way of 1-step Approval process in order to proceed further.
Suppose if Contract Operations Team created a new Contract and submitted for my Approval as below,


Approval Status in Contract Operations User Interface

and Approval Status in Approver User Interface as below


Approval Status in Approver User Interface

Approver can Reassign this process, or Approve/Reject which changes the Overall Status accordingly.

Now let us implement Chatter way of Approval along with the above method additionally.

To do this
1. Enable Chatter Feed Tracking for Contract Object. See Enable Feed Tracking for Objects
    ( Note : Feed Tracking can be enabled for only 20 fields per Object )
2. Create a New Template by navigating to the path below,
    Your Name ➤ Setup ➤ Create ➤ Workflow&Approvals ➤ Post Templates
    Select the fields that need to be displayed in the chatter post once submitted for approval.
    ( Note : Remember there is a limitation of only 4 fields )

Chatter Post Template
Now on clicking "Submit for Approval"

Chatter Post in Contract Record


then Chatter Post in Approver user interface,



Also this way of approval can be more dynamic and faster by way of adding comments without pushing the record back and forth for approval as below,




Consider a situation where Approver has access to Salesforce Chatter in his iPhone or Android Device. Hence the Approver can Approve or Reject the record by clicking respective buttons in the chatter post, without navigating to the Contract record or to "Items to Approve" in Home Page or even without logging into Salesforce application.