function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
apex sfdevapex sfdev 

Where does the Triggers reside in MVC pattern?


I am in confusion to identify the role of triggers in MVC pattern, some one is saying that triggers operates with database and it comes under model part and some one saying that triggers controlls the data to be inserted or updated to the database and comes to controller part of MVC. Please tell me the role of triggers in MVC pattern.

Thanks.
Best Answer chosen by apex sfdev
ManojSankaranManojSankaran
Hi Bala,

It depends on the way in which you are using this trigger. For example, Let say you are using the trigger for validating any data, then we can call it to be a part of "controller".

If we are using the trigger to create and query any data from the table, in that situation we can call the trigger as a part of "Model".

If it really answers your question mark is as answer.

Thanks
Manoj S
 

All Answers

ManojSankaranManojSankaran
Hi Bala,

It depends on the way in which you are using this trigger. For example, Let say you are using the trigger for validating any data, then we can call it to be a part of "controller".

If we are using the trigger to create and query any data from the table, in that situation we can call the trigger as a part of "Model".

If it really answers your question mark is as answer.

Thanks
Manoj S
 
This was selected as the best answer
Amit Chaudhary 8Amit Chaudhary 8
Please check below post.
1)http://amitsalesforce.blogspot.in/2015/04/model-view-controller-mvc-paradigm.html

1) A controller can send commands to its associated view to change the view’s presentation of the model . It can also send commands to the model to update the model’s state. According to Salesforce : How the interface actions. Controllers are used to perform the actions whenever users interact with visual force.

2) A model notifies its associated views and controllers when there has been a change in its state. This notification allows the views to produce updated output, and the controllers to change the available set of commands. A passive implementation of MVC omits these notifications, because the application does not require them or the software platform does not support them. According to salesforce :- What schema and data does salesforce uses 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.

3) A view requests from the model the information that it needs to generate an output representation.
According to Saleforce :- How the schema and data is represented. Visualforce is used to present the data to users.


M - Model (Object, Fields, Relationships, Apex Classes)
V - View (Visualforce page, Pagelayouts, Record Types, Force.com Sites, Components)
C - Controller(Validation Rules, Controllers in a Visualforce page)


Let us know if this will help you

Thanks
Amit Chaudhary