Are you aspiring to be a software application developer? Do you want to build your own application on the Force.com platform? If your answer to these questions are yes, then you should definitely consider becoming a Salesforce developer.
In my previous blogs, I have discussed about Salesforce, Salesforce certifications and also shown you to build a custom application using the declarative options available in Salesforce. In this blog, I will discuss about the programmatic options available in Salesforce to develop your application.
MVC Architecture
Before I dive into building an application using Visualforce and Apex, I will first discuss about the Salesforce Model-View-Controller architecture. Below is a diagram that outlines the Salesforce Model-View-Controller architecture along with the different Salesforce components.
Model: The model is your Salesforce data objects, fields and relationships. It constitutes of standard (Account, Opportunity, etc) and custom objects (objects you create).
View: The view represents the presentation of the data i.e the user interface. In Salesforce, the view constitutes of the visualforce pages, components, page layouts and tabs.
Controller: The controller is the building block of the actual application logic. You can perform actions whenever the user interacts with visualforce.
Salesforce in Action
To be a Salesforce developer, you need to first know how Salesforce applications work and getting Salesforce PD1 Certification would be the best choice. Below is an image which gives you the complete picture of Salesforce in action. The client or user either requests or provides information to the Salesforce application. This is generally done using Visualforce. This information is then passed on to the application logic layer, written in Apex. Depending upon the information, data is either inserted or removed from the database. Salesforce also provides you with the option of using web services to directly access the application logic.
A Salesforce developer can approach development either using the declarative or programmatic options. Below is an image which provides you with details on both the declarative and programmatic approaches available at each of the user interface, business logic and data model layer. To build your user-interface, you can either use the declarative approach which is using page layouts and records types or use programmatic approach like visualforce pages and components. Generally, you should use programmatic approach only when you can not achieve the necessary user-interface using the declarative approach. To develop your application’s business logic layer you can either use the Salesforce declarative options of workflow, validation rules and approval processes or use programmatic approach like triggers, controllers and classes. To access the data model, you can use the declarative approach using objects, fields and relationships. You can also access the data model programmatically using metadata API, REST API and bulk API.
We have seen how Salesforce applications work, the MVC architecture used for development in Salesforce and the two different approaches that are available for a Salesforce developer. Now, let me discuss about Visualforce and Apex.
Visualforce
To build applications on the Salesforce platform you need to know how to develop user-interface and write application logic. As a Salesforce developer, you can develop the user-interface using Visualforce. Visualforce is the user-interface framework for the Force.com platform. Just like how you can use javascript Angular-JS framework to build user-interfaces for your websites, you can use Visualforce to design and build user-interfaces for your Salesforce applications. You can learn more from the Salesforce admin training.
You can use visualforce whenever you need to build custom pages. Few examples of situations where you can use Visualforce are:
- To build email templates
- To develop mobile user-interface
- To generate PDF’s of data stored in Salesforce
- To embed them into your standard page layouts
- To override a standard Salesforce page
- To develop custom tabs for your application
A visualforce page consists of two primary elements:
- Visualforce Markup – The visualforce markup includes the visualforce tags, HTML, JavaScript or any other web-enabled code.
- A Visualforce Controller – The visualforce controller contains the instructions that specify what happens when a user interacts with a component. The visualforce controller is written using Apex programming language.
You can take a look at a simple Visualforce page code along with the different components below:
Below I have shown you the steps to write a simple visualforce page for displaying countries and their currency values:
Step 1: From Setup, enter Visualforce Pages in Quick Find box, then select Visualforce Pages and click New.
Step 2: In the editor add the following code to display country and its currency value:
<apex:page standardController = “country__c”>
<apex:pageBlock title="Countries">
<apex:column value="{!country__c.Name}"/>
<apex:column value="{!country__c.currency_value__c}"/>
</apex:pageBlock>
</apex:page>
To learn in-depth about Workflow in Salesforce, sign up for an industry-based Salesforce course.
Apex
Once you are done developing the user-interface, as a Salesforce developer you need to know how to add custom logic to your application. You can write controller code and add custom logic to your application using the Apex programming language. Apex is an object oriented programming language that allows you to execute flow and transaction control statements on the Force.com platform. If you have used the java programming language before then you can easily learn Apex. Apex syntax is 70% similar to that of java.
You can use Apex whenever you want to add custom logic to your application. Few examples of situations where you can use Apex are:
- When you want to add web and email services to your application
- When you want to perform complex business processes
- When you want to add complex validation rules to your application
- When you want to add a custom logic on operations like saving a record
Below is a screenshot of Apex code along with its different components like looping statement, control-flow statement and SOQL query: