Salesforce MVC Architecture
Model View Controller (MVC) Architecture in Salesforce is a software pattern that separates the representation of information from the user’s interaction with it.
Features Of Salesforce MVC Architecture
- We can write our VIEW pages using SFDC visual force (VF pages).
- Each VF page is associated with a Controller.
- We can make use of already-built Standard controllers(like Account, Contact, etc) or we can write our controller using Apex language. Apex is Object Orientated(proprietary Language of Salesforce) and very much similar to JAVA.
- We can also write Model Classes using Apex.
Modules In Salesforce MVC Architecture
MVC architecture in the Salesforce pattern contains three modules:
Model (Database Layer)
The schema and data in Salesforce use to represent the system completely. In Salesforce, we can say that sObjects are the model as every entity in Salesforce is mapped to some sObject. (sObjects are any objects that can be stored in the Salesforce platform database). It is a data model for all the objects which helps us to know about the relationship between them and each of their fields.
View (User Interface Layer)
How the schema and data are represented. Visualforce is used to present the data to users. It means how the UI will look like.
Controller (Business Logic Layer)
How the interface actions. Controllers are used to perform the actions whenever users interact with visual force. It contains all the business logic that helps us to communicate with the database from the UI. for example, apex Classes.
- Visual Force pages, Page Layouts, and Tabs come under the View Layer of Model View Controller in Salesforce.
- Workflows, Apex Classes, and Triggers come under the Controller part in the Model View Controller in Salesforce.
- Objects, Fields, and Relationships come under the Model Layer of the Model View Controller in Salesforce.
Benefits Of Using Salesforce MVC Architecture
The layers have clear separation so it allows greater reliability if we want to change any layer. For example, it can change the look and feel of an application without recompiling the Model or Controller code.
2. High Reuse And Adaptability
MVC provides multiple types of views all accessing the same code.
3. Very Low Development And Life Cycle Cost
It makes it possible to have lower-level programmers develop and maintain user interfaces. Development time can be significantly reduced because Controller programmers focus solely on transactions and view programmers focus solely on presentation.
4. Easy To Maintain
The separation between layers makes it easier to maintain, test, and deploy apps.