Friday, December 21, 2012

Querying sObject Relationships in Apex Programming Language

In Force.com Platform, many objects are related to each other as a parent or child. We call this as parent-to-child and child-to-parent relationships. In our article about sObject, we learnt that sObject in Apex programming language represents an object in Force.com Platform. 

So, just like the objects in Force.com platform, sObject in Apex is also aware of relationships. Let us see this with few examples.

The object Contact is related to the object Account by child-to-parent relationship. Contact is child, Account is parent and relationship name is Account. See the following lines code where it retrieves the Contact sObject and at the same time obtains parent information as well.
   Contact c = [SELECT Id, Name, Account.Name FROM Contact WHERE FirstName='John' LIMIT 1];
   Account a = c.Account;
   System.debug (a.Name);
   System.debug (c.Account.Name);

When we are retrieving the Contact sObject into c, since we are reading Account.Name as part of the query, we are able to read c.Account as Account sObject. Hence able to read the parent account name. In Account.Name in the query, Account is the relationship name.

Now another scenario. The object Account is related to the object Contact by parent-to-child relationship. Account is Parent, Contact is child and relationship name is Contacts. See the following lines of code where it retrieves the Account sObject and at the same time retrieves all its Contacts as children.
   Account a = [SELECT Id, Name, (SELECT FirstName, LastName FROM Contacts) FROM Account WHERE Name='ABC Corp'];
   System.debug (a.Name);
   List <Contact> children = a.Contacts;
   System.debug('Number of contacts: ' + children.size());
   for (Contact c: children) {
   System.debug(c.FirstName);
   }


When we are retrieving the Account sObject into a, we are reading its children Contacts using a sub query. Hence able to extract all its children sObjects into an array and read them out as individual sObject.

Happy cloud computing using Salesforce!

Thursday, December 20, 2012

sObject in Apex Programming Language

In our article, Overview of Apex Programming Language, we learnt that Apex is data focused and programming in Apex is like writing stored procedures in a database. The very important element of the language which makes the integration with the database very easy to use is sObject. We briefly looked at it in our previous article, Data Types in Apex. Let us have a detailed look in this article.

sObject represents an Object in Force.com platform. We know that each object in Force.com platform, standard or customized, is just like a table in the database. sObject data type in Apex corresponds to these database objects. In other words, it is an object that can be stored in the Force.com platform database.


The following example creates an empty Account Object and assigns it to sObject. As you can see, it is just like instantiating a class.


    sObject s = new Account();
Instead of the generic sObject, you could instantiate it with specific type Account which is an sObject as well. 

    Account a = new Account();
You can instantiate the object with initial values or assign the value after instantiating it like below.

    Account a = new Account(Name='ABC Corp');
The above statement is same as the following 2 statements,

    Account a = new Account();
    a.Name = 'ABC Corp';

You can retrieve an sObject using Salesforce Object Query Language (SOQL) and Salesforce Object Search Language (SOSL). You also use sObject while executing Data Manipulation Language (DML). We will sure explore all the three - SOQL, SOSL and DML in detail in future articles. 


The following example uses SOQL to retrieve an sObject -
    Account a = [SELECT Id, Name, Description FROM Account WHERE Name='ABC Corp'];
You can then read the individual field values using the dot notation like a.Id, a.Name or a.Description.

You can retrieve an array of sObject as below -

    Account[] a = [SELECT Id, Name, Description FROM Account]; 
Another specialty of sObject is using an sObject, you can get related parent and child sObjects and access their fields. We will explore this one as well in detail in one of our future articles.


Happy cloud computing using Salesforce!

Tuesday, December 18, 2012

Apex Trigger in Force.com

Apex Trigger in Force.com platform is a procedure written in Apex programming language that operates on an object at the defined events. The events could be before or after records are inserted, updated, or deleted in the database.

When the trigger is running, there could be several records meeting the criteria. For example, you have a trigger defined on object Account, at event before inserting. When the trigger is running there could be many Account records that are being inserted. Your trigger procedure runs on all these Accounts. As you can see since the trigger is fired when database records are manipulated, your trigger code is probably further manipulating the data that is being stored.

System.Trigger class provides all the information related to the trigger that is being fired. Within the Trigger procedure, using the instance of this class you can figure out the operation that triggered the event. Using the same System.Trigger class, you can also have access to the new data if insert/update trigger as well as the old data prior to the operation if it is update/delete trigger.

Triggers are defined on the objects. On object definition detail page, there is a section called Triggers. This is where you can add/manage triggers. Trigger code is compiled when it is saved and must compile successfully to be able to save.

Apex Trigger procedure syntax is -

trigger TriggerName on ObjectName (events) {

code_block

}

where events can be comma separated list of one or more of the following -
  • before insert
  • before update
  • before delete
  • after insert
  • after update
  • after delete
  • after undelete
Any database changes made by trigger are automatically committed on successful completion of the trigger, otherwise changes are rolled back.

That is in brief about the Apex Trigger. You can understand the workings of this better by implementing some of the triggers.

Happy cloud computing using Salesforce!

Tuesday, December 11, 2012

Data Types in Apex Programming Language

Apex is a strongly typed, object-oriented programming language. Just like any other programming language, Apex has variety of data types that you can use. Let us see that list in this article.

Primitive Types - This data types include String, Integer, Long, Double, Decimal, ID, Boolean, Date, Datetime, Time and Blob. All these data type variables are always passed by value in methods.  Another point to note is in Apex, all variables are initialized to null when declared. You must explicitly initialize to non-null values before using.

sObject Types - This is a special data type in Apex. sObject is a generic data type for representing an Object that exists in Force.com. It could be Standard object like Account, Opportunity etc., or Custom object that you define.  Following are some of the examples of sObject variables -

    sObject s = new Account();
    Account a = new Account();
    CustomO__c c = new CustomO__c();

As you can see above, your custom objects have an extension of __c to distinguish from the Force.com standard objects. Fields from the sObject variable can be accessed using the dot notation. For example,
        
    a.Name = 'ABC Corp';

Collections - Apex has 3 types of collections. Lists, Sets and Maps.
  • A list is like an array, a sequential collection of elements with first index position as zero. List can contain elements of primitive types, sObjects, user-defined objects, Apex objects or even other collections. A list can contain up to four levels of nested collections. List can contain duplicate elements.
  • A set is also a collection of elements and elements can be of any data type. Unlike list, set contains unique elements and elements in set are not in any specific order. 
  • A map is a collection of key-value pairs. Keys and values can be any data type. Keys are unique and map elements must be accessed by the key as the order of  map elements are not reliable.
Enums - Just like in other programming languages, Enum type represents a fixed set of named constants. 

Apex variables can be objects created from user defined Apex classes or objects created from  system supplied Apex classes as well.

Happy cloud computing using Salesforce!

Friday, December 7, 2012

Overview of Force.com Apex Programming Language

We have been studying how one can build and customize applications using the Force.com Platform point and click method. A very powerful and sophisticated business application can be built using the platform and yes, just using the point and click method. But there are always times where your organization may have a requirement that the platform may not support. One way this custom functionality can be implemented is using the Force.com programming platform, Apex.

Just like everything else with Force.com, Apex which is part of the platform is fully controlled and hosted  by the platform. It runs in the cloud on Force.com servers.

Apex is a strongly typed, object oriented programming language. Code is compiled and stored as metadata. When executed by the end-user,  the Apex run time interpreter reads the compiled instructions from the metadata and returns the result.

Apex allows developers to add business logic to system events like button clicks and data updates. 

  • Apex can be invoked through the use of triggers. 
  • Apex classes can be scheduled to run at specific times.
  • Web service methods can be implemented in Apex and and can be invoked using Ajax Toolkit.
  • Apex code can be executed on the fly by executing it as anonymous block.

Apex language is very much data focused. It provides calls for data manipulation, querying and looping through the data but does not provide any support for rendering elements in the user interface. If you have any database development exposure, you can very much relate coding in Apex to writing database stored procedures.

Apex also supports test driven development process by allowing you to  create and execute unit tests. 

We will be exploring 'Programming in Apex' in detail in our future articles.

Happy cloud computing using Salesforce!

Chatter, the Salesforce Social Platform

The chatter from the Salesforce platform allows for easy collaboration and knowledge sharing between departments and employees in any organization using the applications built on Force.com platform. It helps  you to be on top of the latest happenings in your organization by connecting with people, following real time updates and sharing information securely.

Let us see some of the features of Chatter application.

Status Updates - You can share your status in real time. Your status update can include a file or a link as well. One who is following your feed can give feedback, comment and engage in a conversation. Status updates helps to keep everyone informed of various updates within the company.

Follow People, Documents and Data - Chatter allows for following not just people, you can follow documents and data as well. You can receive status updates on the progress of the document you are following. Updates on the data can be followed too. For example, you are interested in knowing how certain opportunities progress and when it closes. You can get those updates right in your chatter! 

Respond to Workflow Approvals - Workflow approvals are built and designed to achieve an effective  flow of business process. When it is your time to act upon to approve any step, you may do so right from your chatter feed.

Group Communication - You can form groups to communicate and share information better. You can have private groups with specific colleagues, or public groups or even customer based groups. Thus, you can have full control on what you want to share and with whom you want to share.

Security and Sharing - Chatter is all about so much of sharing and receiving updates. But there is always an underlying sharing model built into the Force.com platform which decides what you can see and act upon. The chatter fully supports this model and ensures that you can see only what you are allowed to see.

These are the overall features of chatter in Salesforce platform. Using the applications built on Force.com platform, you can monitor and act upon almost anything that matter most to you within an organization to work together in teams.

Happy cloud computing using Salesforce!

Approval Process in Force.com

In some of the recent articles we studied about Workflow and how to set them up in Force.com platform. The other part of workflow is Approval Process. Workflow is triggered when a record is added or updated. Approval process is triggered when the user manually clicks on 'Submit for Approval' button.

An approval process consists of steps and actions. An approval process is a sequence of steps that finally declare the record as approved. You can also define who must approve at each step. Thus, by defining approval process, records that need different approvals are submitted to the right people at the right time. And just like workflows, we can setup actions as part of the approval process as well. 

An approval process consists of the following -

1. Process Definition - Process definition contains Name and Description. Entry Criteria can be specified here for setting a filter to find the records for which you are applying the approval process. You can specify the user for automated approval routing for approval steps and also specify if the approver along with the administrator can edit records that are pending approval. Email template can be specified to use for notifying approvers. The approval page can be designed to display appropriate details for approver to see while approving. You can specify initially who can submit the records for approval.

2. Initial Submission Actions - You can specify actions to execute when a record is initially submitted for approval. Actions could be Task, Email Alert, Field Update or Outbound Message.

3. Approval Steps - You can define one or more approval steps in the approval process. Approval steps are numbered that determines the order. Entry criteria can be specified for each step allowing records to enter that step only if it meets the criteria. You can specify who should approve the records that are in this step. For each step you can specify approval and rejection actions.

4. Final Approval Actions - You can specify actions to execute at the end of the approval process, that is after the record has passed all the necessary steps and approved.

5. Final Rejection Actions - Just like final approval actions, you may specify rejection actions to indicate what must happen if rejected.

6. Recall Actions - An approval request can be recalled. Hence you could specify actions to execute if recalled.


As you can see, the Force.com platform lets us cover all the possibilities. As you can also imagine, how quickly an approval process can get too complicated, a through planning and designing is a must before we venture into setting up approval process.

Happy cloud computing using Salesforce!





Thursday, December 6, 2012

Creating Workflow Action for assigning a task in Force.com

One of the workflow actions that we can set up to execute in Force.com platform is 'Task Assignment'. Let us explore the steps involved in setting up this type of workflow action using Force.com platform.

From the App Setup -> Create -> Workflow & Approvals -> Tasks, you can create a new Task and use it while setting up workflow actions.

Otherwise, while setting up workflow actions you can click on 'New Task'. Both actions take you to the same page.

If you had come into this page via the 1st route mentioned above, you will need to select the object to which this task belongs to.  In the 2nd route, the object you have selected for the workflow rule is automatically selected for the action as well.

Enter task assignment information. This can be set to a 'User', 'Role', 'Owner' or 'Creator'. Select Status and Priority for the task. Enter the Subject or Title for the task.

Set the due date for the task. This can be set based on a date field of the record or simply set it to the rule trigger date.

You can also check the 'Notify Assignee' box to send out an email notification to the assigned user  when the task assignment is made.



Save your work. If you created a new task, go ahead and associate it with a workflow rule and you will have a workflow action for assigning a task.


Happy cloud computing using Salesforce!

Monday, December 3, 2012

Creating Workflow Action for updating a field in Force.com

One of the workflow actions that we can set up to execute in Force.com platform is 'Updating a Field'. Let us explore the steps involved in setting up this type of workflow action using Force.com platform.


From the App Setup -> Create -> Workflow & Approvals -> Field Updates, you can create new Field Update and use it while setting up workflow actions.

Otherwise, while setting up workflow actions you can click on 'New Field Update'. Both actions take you to the same page.


Enter Name for the Field Update you are setting up. If you had come into this page via the 1st route mentioned above, you will need to select the object to which this field update belongs to.  In the 2nd route, the object you have selected for the workflow rule is automatically selected for the action as well.

Field to Update need to be specified. Based on the data type of the field selected for update, you get different options for specifying new field value. 


  • If it is a nullable field type, you can specify a blank (null) value for the new field. 
  • You can use a formula to set the new value. For example Today() + 7 for a date field.
  • For Record Owners, you can choose the user for new assignment.
  • For a boolean (True/False) type of field, you can select True or False as new value.
  • Another type of field is 'Picklist' where possible values are predefined. If you are updating this type of field, you can set the value to one above or below the current choice or to a specific predefined value.

Re-evaluate Workflow Rules after Field Change checkbox allows you to re-evaluate all workflow rules on the object after the field value is updated and hence trigger any workflow rules if the criteria are met. 

Save your work. If you created a new field update, go ahead and associate it with a workflow rule and you will have a workflow action for updating a field.


Happy cloud computing using Salesforce!

Friday, November 30, 2012

Setting up global email address for your organization in Force.com

When you set up workflow to send out emails in Force.com platform, you can set the from address to a generic email address of the organization. For example, instead of your own email address you could use contact@yourcompany.com. 

To be able to set these standard email address as from email address, you first need to set it up using a feature called organization-wide address.

Go to Administration Setup -> Email Administration -> Organization-Wide Addresses. By clicking on the 'Add' button you can enter an email address. You can use this across all profiles or limit to only certain profiles to use as from address.

Once the email address is added, a verification email is sent to that email address. The verification email provides a link where you can go and verify the email address. Until the verification is done, platform keeps that email address in 'Verification Request Sent' status. Once the verification is done, status changes to 'Verified'.

You will be able to use any of the verified status organization-wide email addresses as from email address for email alerts.

Happy cloud computing using Salesforce!

Creating Workflow Action for sending out email alerts in Force.com

One of the workflow actions that we can set up to execute in Force.com platform is 'Sending out Email alerts'. Let us explore the steps involved in setting up this type of workflow action using Force.com platform.

From the App Setup -> Create -> Workflow & Approvals -> Email Alerts, you can create new email alerts and use it while setting up workflow actions.

Otherwise, while setting up workflow actions you can click on 'New Email Alert'. Both actions take you to the same page.



Enter Description for the Email Alert you are setting up. If you had come into this page via the 1st route mentioned above, you will need to select the object to which this email alert belongs to.  In the 2nd route, the object you have selected for the workflow rule is automatically selected for the action as well.

Email Template need to be specified. There are some standard email templates provided by the platform. If you need your own customized template, you must set up your email templates  in advance via Administration Setup -> Communication Templates -> Email Templates.

Email Recipients must be specified. There are 2 different ways you can specify who should receive the alerts. If your alert is going to someone in your organization, look for the recipient by Recipient Type. Based on your selection in the type, you get the Available Recipients list. You can select recipients among them. You may also specify up to 5 additional free form email addresses at the bottom section, if the recipient is someone outside your organization network in the Force.com platform.

From Email Address can be set to workflow user's email address or one of the organization-wide address that has been set up.

Save your work. If you created a new email alert, go ahead and associate it with a workflow rule and you will have a workflow action for sending out emails.

Happy cloud computing using Salesforce!

Thursday, November 29, 2012

New Task option for Add Workflow Action in Force.com is missing

One of the workflow actions that we can set up in Force.com platform is a task assignment. So, you have a new custom object and you are setting up workflow rules for this object. You want to add a new task for workflow action. However, on the 3rd step of creating workflow rule, you do not see 'New Task' option under 'Add Workflow Action'. So, what are you missing?

When creating the custom object, there was an optional feature called 'Allow Activities'. You probably did not check that option. Go to the Edit page for your custom object and scroll down. You will see a section called 'Optional Features'.



Check 'Allow Activities', save and add workflow action now. The 'New Task' option will be available.

Happy cloud computing using Salesforce!

Wednesday, November 28, 2012

Setting up Workflow Actions in Force.com

As we learnt in Creating Workflow Rules in Force.com, the 3rd step is to specify the workflow actions that will be executed when the rule criteria are met. Let us now learn how to set up workflow actions in Force.com platform.

When you are in 3rd step of the workflow rule creation process which is specifying workflow actions, you will see 2 different sections. Immediate Workflow Actions and Time-Dependent Workflow Actions.

Immediate Workflow Actions - As the name indicates, the actions set up here executes instantly when the rule criteria are met.

Clicking on the 'Add Workflow Action' button gives you option for either selecting an existing action or creating a new action. As we learnt before in Workflow and Approval Process article, the action could be a Task, Email Alert, Field Update or Outbound Message. You can set up one or more actions of the same type or combination.

Time-Dependent Workflow Actions - Actions that you can set up in this section are same as above but they are time dependent. You add a 'Time Trigger' first and then add workflow actions  to that time trigger. The time trigger adds a delay before the action executes. This delay could be in terms of Days or Hours and could be before or after. You can add multiple time triggers. And just like the immediate workflow actions, you can set up one or more more actions of the same type or combination to each time trigger.

For example, you can set up field update and task assignment actions to execute 5 hours after an opportunity is closed. You can set up task assignment and email alert actions to execute 30 days after an opportunity is closed.

We will see each of the action types in detail in our future articles.

Happy cloud computing using Salesforce!

Workflow Rules Filter Logic in Force.com

In the article Understanding Workflow Rule criteria we left out the section 'Add Filter Logic'. Let us explore now and see how can we utilize this feature in Force.com platform. 

The Workflow Rule Criteria in Force.com platform gives two different choices to run the rule - 1. criteria are met. 2. formula evaluates to true.

In the 1st choice, when we are defining the criteria, as you can see there are multiple rows we can fill in. At the end of each row, you see an 'AND' literal. That means criteria specified in each row is logically ANDed to come up with the final criteria.



Let us take a simple example. 

Say our requirement is to find all Opportunities for new customers with amount is more than 10000.

1st Row - Opportunity: Type equals New Customer
2nd Row - Opportunity: Amount greater than 10000

This translates the rule criteria into -

(Opportunity: TypeEQUALSNew Customer) AND (Opportunity: AmountGREATER THAN10000)

which is in other words, (Row 1 AND Row 2)

The rule criteria works fine and we find the records we want. Now let us change our requirement a bit.  

Say our requirement is to find all Opportunities for new customers with amount is more than 10000, and all other opportunities if the amount is more than 25000 regardless of new or existing customer.


1st Row - Opportunity: Type equals New Customer
2nd Row - Opportunity: Amount greater than 10000
3rd Row - Opportunity: Amount greater than 25000


This would translate to -


(Opportunity: TypeEQUALSNew Customer) AND (Opportunity: AmountGREATER THAN10000AND (Opportunity: AmountGREATER THAN25000)


or (Row 1 AND Row 2 AND Row 3)

As you can see, this doesn't result into exactly what we are after. Instead, the result of this would be exactly same as the 1st expression. This is where 'Filter Logic' is applied to get the right result. Click on the 'Add Filter Logic' link at the bottom. You will see the following -



See the Filter Logic that says 1 AND 2 AND 3. We change this into (1 AND 2) OR 3 to get our result. Now the rule criteria changes into -

((Opportunity: TypeEQUALSNew Customer) AND (Opportunity: AmountGREATER THAN10000)) OR (Opportunity: AmountGREATER THAN25000)

Thus getting us all opportunities of amount more than 25000 along with new customer opportunities with amount more than 10000.


Now let us change our requirement once again.  

Say our requirement is to find all Opportunities for new customers with amount is more than 10000, and all other opportunities if the amount is more than 25000 regardless of new or existing customer,  only if the opportunities are at negotiation stage.

1st Row - Opportunity: Type equals New Customer
2nd Row - Opportunity: Amount greater than 10000
3rd Row - Opportunity: Amount greater than 25000
4th Row - Opportunity: Stage equals Negotiation/Review

And we have Filter Logic from the previous step as (1 AND 2) OR 3. Now we need to add the 4th row into the logic as per our new requirement.

We have 2 expressions separated by an OR. We need to make sure both returns the opportunities that are only at negotiating stage. So ideally we AND our 4th row into both, giving us (1 AND 2 AND 4) OR (3 AND 4). We could also take out the 4 outside and come up with ((1 AND 2) OR 3) AND 4

That is how filter logic is used while creating workflow rules. This same filter logic is useful while filtering report data as well. As you can see it can get tricky with complex filtering requirements. Choosing the right filter and grouping them in proper parentheses will make it easier.

Happy cloud computing using Salesforce!

Tuesday, November 27, 2012

Understanding Workflow Rule criteria in Force.com

In the article Creating Workflow Rules we learnt the steps involved in creating workflow rules in Force.com platform. In this article let us explore the step of defining the rule criteria. 

In Step 2 while creating the workflow rule, after you enter the rule name and description, you have 2 sections - Evaluation Criteria and Rule criteria as shown below. 



They both work together to determine when the rule is executed. Let us go in the reverse direction. First let us see what is Rule Criteria and then Evaluation Criteria.

Rule Criteria - Rule Criteria defines when to trigger the rule. You can define this based on the combination of field values or based on a formula evaluation. 

Let us take a very simple example to understand this better. 


  • Say you have an object called Invoice with a field named Status of values 'Open' and 'Closed'. 
  • You want to perform some action when the status of each invoice record is closed.
  •  You would define the rule criteria as 'Status' equals 'Closed'
This defines the criteria to trigger the rule when status is changed to closed for invoice record. However it is not that straight forward. As we can see below the evaluation criteria controls this further.

Evaluation Criteria - This defines when to evaluate the rule criteria. Only when this criteria is met, the rule criteria is evaluated and triggered if met.  There are 3 different choices.

  • created - This indicates evaluate the rule criteria each time a record is created. That means rule is evaluated only once when record is created. Hence in our example this option would indicate each time when an Invoice record is created, since evaluation criteria is met, rule criteria is evaluated and hence checked if the Invoice is created with 'Closed' status. If it is not created with 'Closed' status, no action is performed. Rule is never triggered again for this record even if the invoice changes to 'Closed' later on.
  • created, and every time it's edited - This indicates evaluate the rule criteria each time a record is created and updated. Hence in our example this option would check if the Invoice status is 'Closed' when a record is created as well as each time the record is updated.
  • created, and any time it's edited to subsequently meet criteria - This is same as the above but the difference is it makes sure when the record is updated the rule criteria is really met as part of the update. In other words, it ignores the record edits that are not relevant to the rule criteria. In our example, say Invoice Status is updated from 'Open' to 'Closed' -  Rule criteria is evaluated and triggered since status was changed to 'Closed'. Now say Invoice record is updated again to correct the customer address zip code - Rule criteria is not evaluated though the Invoice status is 'Closed'. Platform will understand that the update is not related to the status change.
That is how we set the rule criteria. On this step there is one more item which is part of rule criteria called 'Add Filter Logic'. We will cover this in the next article.

Happy cloud computing using Salesforce!

Monday, November 26, 2012

Creating Workflow Rules in Force.com

In one of our previous articles we learnt what is Workflow and Approval Process in Force.com platform and how it is important for any organization. We also learnt that workflow is made up of Workflow Rules. 

Workflow rules define rules for workflow step. It defines the criteria, the schedule and the execution plan for the workflow actions. In this article let us explore how to create those rules using the Force.com platform.

To create a workflow rule go to App Setup -> Create -> Workflow and Approvals -> Workflow Rules. Then click on the 'New Rule' button.


Step 1 - You select the object to which your workflow rule applies. Each rule applies to a single object
Step 2 - You enter the rule name and description. You define the rule criteria.

Step 3 - You specify the workflow actions that will be executed when the rule criteria are met.

Save the workflow rules and activate it from the workflow rule detail page. As far as the overall steps go it is as simple as this. But both Step 2 and Step 3 are much involved. Both steps deserve an article itself to get a good understanding. Coming soon!

Happy cloud computing using Salesforce!

Saturday, November 24, 2012

Workflow and Approval Process in Force.com

In any organization there are number of scenarios where processes are so standard and could be easily automated to reduce the delay or gap between the steps. The Workflow and Approval Process components in Force.com platform covers these requirements. 

Creating the  business logic based on the requirements and implementing the workflow process in the platform is an easy task just like other features we have been exploring in the previous articles. We create rules to customize processes. Using these rules we can automate the processes. 

The workflow component in the Force.com Platform allows us to perform the following -

Assigning Tasks. Tasks can be assigned to a user, a role or the record owner. For example, automatically assign a task to a representative for conducting customer satisfaction survey after a week of selling your product or service.

Field Updates. Value of a field in a record can be updated to new value. For example, when Status of an order is changed to 'Closed', the closed date can be automatically set.

Send Email Alerts. Emails can be sent out to one or more recipients. For example, when the status of an order is set to 'Shipped', email can be automatically sent out to the buyer.

Send API Messages. XML format API messages can be sent out to designated listener. For example, send out an outbound API message to an external HR System for initiating the expense reimbursement process.

Workflow automates processes. Approvals take care of the automatic approval of a record. An approval process can specify when to approve and who should approve a record. You can also specify the actions to take when the approval process is executed. 

Let us see some classic examples for approval process usage. 

*    An employee leave approval policy where different people or roles or departments have to approve depending on various criteria. 

*    Expense report approval policy where if within a certain amount may be it is automatically approved, and beyond  certain amount it may need approval by different people.

*    Employee recruiting process where depending on which department employee is being hired, process needs approval from different people starting from opening up that post in the organization to employee coming on board.

As you can see Workflow and Approval process could be so much useful to any organization. In the upcoming articles let us explore how to configure these components in the platform.

Happy cloud computing using Salesforce!

Wednesday, November 21, 2012

Page Layout Editor in Force.com

As you might have seen so far, when you added custom objects, you could make the platform automatically create pages for data entry/editing. If you have only few fields, it is not a problem. But when you add number of fields, you certainly want to move things around, organize how those fields are grouped together, set which fields are visible/read only or required and so on. There comes handy the Page Layout Editor.

Force.com platform provides the tool Page Layout Editor using which one can easily organize the page just by simple point and click and drag things around. Let us see how to access this tool and what all it has to offer.

Go to the object definition detail page via App Setup -> Create -> Objects and then clicking on the link for your object label and scroll down a little to see Page Layouts section. You can click on 'New' to create a new Page Layout or click on Edit for an existing one. Go ahead and click on Edit. The page displayed is the Page Layout Editor.

Page Layout Editor displays your current page layout along with a toolbar and a palette at the top with different user interface elements that you can use. As you can see each and every control and section in the page layout is clickable. Then you can move it around by simply dragging and dropping it to the required location. You can set the properties by clicking on the wrench icon. You can also delete it altogether by clicking on the delete icon.

The palette provides 3 different categories - Fields, Buttons, Related Lists. Fields category provides you 'Section' and 'Blank Space' user interface element along with all the fields. You can simply drag and drop it on the page layout wherever you want. Buttons category provides you the list of buttons you could have. Related lists allows you to manage the detail records lists. 

The toolbar provides buttons for saving and previewing. Check out the preview, you can preview using different roles. This is important because though you have organized all the fields and sections to your satisfaction, users in all different roles may not see it the same due to some fields being not visible to them etc.

Also, as you can see when you scroll down the page layout both the toolbar and the palette moves with it and hence always visible, making it so easy to work with the editor.

That is such a simple and easy to use tool. At the same time quite powerful as to what you can do!

Happy cloud computing using Salesforce!

Monday, November 19, 2012

Data validation rules in Force.com

We all make mistakes when entering data and we expect the application to catch all those errors. For example a 'Quantity' field in an order submission form. Does it make sense if user enters a zero value or a -ve value for it? Applications need to have a way of verifying if the data entered is sensible. Force.com platform provides a built-in feature, an easy way to catch all those errors by letting the developers define validation rules for the fields.

Let us learn the steps involved in putting together a validation rule. 


Step 1 - Decide the object and the field for which you will be adding a validation rule. For your object of choice go to its object definition detail page via App Setup -> Create -> Objects and then clicking on the link for your object label.


Step 2 - There you will  see a link (towards the top) called 'Validation Rules'. Or just few sections below, you will see a section called 'Validation Rules' with a button 'New'. Either click on this 'New' button or hover over the top link and click on the 'New' button there.

Step 3 - You will be taken to a page where you are allowed to enter Rule Name, Description, Error Condition Formula and Error Message to display. Error Condition Formula section is where we spend our time coming up with the validation rule. But wait a minute! Have you read my previous article Custom Formula Fields in Force.com? If you have read it and have spent enough time to come up with 'Custom Formula' Fields, this section should look very familiar. Go ahead, play with this section and put together your validation rule.

Step 4 - Enter the Error Message you want to display when the 'Error Condition Formula' you have setup is true and the location for the message to be displayed.

Go ahead and save your validation rule. That was quick and easy isn't it?

Happy cloud computing using Salesforce!

Friday, November 2, 2012

Custom Formula Fields in Force.com

The general fields store values entered by users. There are times we want to apply calculation on these values and come up with the result. Formula fields in Force.com platform does the exact same thing.  Formula fields are nothing but the calculated fields. In other words, you apply a formula on the fields that store data. This calculates the required value and returns the result without changing the underlying data.

Force.com platform provides all required operators including logical operators and many functions to perform our calculations. Go ahead and try it out.

Add a new custom field and select 'Formula' for Data Type. Continue with the next step, enter the usual Field Label and Name, also select the Return Type. Return type is the type of the result you are expecting from your calculation. Move on to next step, switch to 'Advanced Formula' tab and this is where all the fun starts. 

There is an editor where you come up with your calculated field or custom formula field. Platform provides you with 4 different options to help you out.

Insert Field - This button provides the list of data storing fields that you could use in your formula.

Insert Operator - This button provides all the operators that platform provides.

Functions - Scroll down this list and see the number of functions you have to come up with your formula. Click on the function and a quick helper text is displayed about the selected function.

Check Syntax - At the bottom of the editor, there is a button called 'Check Syntax'. When you have your formula ready, you don't have to store it without knowing whether it is syntactically correct. Use this 'Check Syntax' button and this will validate your formula.

That is it! With the help of these 4 options you can write a simple or complex formula, validate    and store it as a Formula Field.

Happy cloud computing using Salesforce!

Tuesday, October 9, 2012

Picklist field and field dependencies in Force.com

Picklist field is a drop-down list. Unlike the simple text field, picklist field consists of predefined values and these appear as options to select for the user. Force.com platform allows you to define 2 types of picklists. 1. Standard Picklist - User can select a single value from the drop-down list. 2. Multi-Select Picklist - User can select one or more values at a time.

In Force.com platform, while adding a new custom field to an object you select the data type as 'Picklist' to create a new Standard Picklist. Or select data type as 'Picklist (Multi-Select)' to create a new Multi-Select Picklist. Then the steps that follow will guide you how to define the list of values for drop-down list, specify the sort order and default value if any. In case of multi-select, you can also specify how many lines should be visible in the scrollable box that is displayed for the user.

Many times there are scenarios where you want to group the related values in different fields and make them dependent on each other rather than displaying all of them in one lengthy drop-down. For example, instead of listing all countries in one single field you may want to give the user a field to select a continent first  and then based on the selected continent you would list the countries belonging to that continent. Thus making the country drop-down list a readable list.

In Force.com platform, this is achieved by field dependencies. Under the custom fields section of an object, there is a button 'Field Dependencies'. This is for setting up the kind of fields we just talked above. 

For example, after adding the Continent and Countries as custom field of type Picklist, you setup the field dependencies. While setting up the field dependencies, you specify the 'Controlling Field' and 'Dependent Field'. Controlling field is the one that filters the options in the other field that is specified as dependent. In this example, you would specify Continent as controlling and Country as dependent. After you specify these 2, the next step will allow you to organize the dependencies just by few clicks on the predefined values for the picklists. You can even preview your picklists. 

Setting up picklists and dependencies in Force.com platform simple and easy. Give it a try!

Happy cloud computing using Salesforce!

Thursday, September 27, 2012

Setting up Relationships with other objects in Force.com

Relationship defines how different objects are associated or linked to each other. In Force.com platform, you set up relationships by creating custom relationship fields on an object. While adding new fields to the object, you select the appropriate data type. Master-Detail relationship or Lookup relationship.

Master-Detail Relationship


This type of field creates a parent-child relationship between objects. This relationship field serves in allowing us to achieve many-to-one and many-to-many relationship between objects.

When you are adding a custom field of this type on an object, the object you are adding the field to works as child object. The other object that you select as 'Related To' is the parent. Hence you are creating many-to-one relationship. The child object record's ownership, sharing and security is determined by the parent object record's setting. In fact, the child object doesn't have a owner field. In other words, the child records are owned by the owner of the parent record and also when the parent record is deleted all its child records are deleted as well.

Many-to-Many relationship can also be achieved using the same relationship field. But we need to understand where this field resides. To achieve many-to-many relationship between  two objects we create a custom object called junction object. This junction object is basically like intersection table between two tables in RDBMS. We create two master-detail relationship fields in the junction object to link with the objects for which we want to create many-to-many relationship.


Lookup Relationship


This type of field creates relationship between two objects in a simple form. Using this you can even link an object with itself. Unlike master-detail relationship, this one is loosely coupled and no cascading deletion. In other words, deletion of records in any object has no effect on the other linked object records. The ownership is maintained independently as well.

So, that is how the relationships between the objects are achieved. Go ahead and try out some.

Happy cloud computing using Salesforce!



Monday, September 17, 2012

Add new custom object in Force.com

In one of our previous articles we added new fields to an object. Now let us see how to add a new object. Objects in Force.com platform translate to a database table. New objects are called custom objects.

New object can be added in Force.com platform under App Setup -> Create -> Objects.  Clicking on 'New Custom Object' button on this page takes you to a page where you can enter your new object name and create the custom object. It allows you to enter name and type for 'Record Name' field as well which is a unique identifier for the record. You can set this to auto generate a number in a specific format as well as shown below.



After you create the object, you can setup user access either using Permission Sets or updating the Profiles under Administration Setup -> Manage Users. Look for 'Object Settings' while editing Permission Sets or look for 'Custom Object Permissions' while editing Profiles.

Our new custom object is ready with the standard fields and waiting for all the new custom fields. Go ahead and get working on them as per our article.

Happy cloud computing using Salesforce!