Trigger Conext
Variable | Usage |
---|---|
isExecuting | Returns true if the current context for the Apex code is a trigger, not a Visualforce page, a Web service, or an executeanonymous() API call. |
isInsert | Returns true if this trigger was fired due to an insert operation, from the Salesforce user interface, Apex, or the API. |
isUpdate | Returns true if this trigger was fired due to an update operation, from the Salesforce user interface, Apex, or the API. |
isDelete | Returns true if this trigger was fired due to a delete operation, from the Salesforce user interface, Apex, or the API. |
isBefore | Returns true if this trigger was fired before any record was saved. |
isAfter | Returns true if this trigger was fired after all records were saved. |
isUndelete | Returns true if this trigger was fired after a record is recovered from the Recycle Bin (that is, after an undelete operation from the Salesforce user interface, Apex, or the API.) |
new | Returns a list of the new versions of the sObject records. This sObject list is only available in insert, update, and undelete triggers, and the records can only be modified in before triggers. |
newMap | A map of IDs to the new versions of the sObject records. This map is only available in before update, after insert, after update, and after undelete triggers. |
old | Returns a list of the old versions of the sObject records. This sObject list is only available in update and delete triggers. |
oldMap | A map of IDs to the old versions of the sObject records. This map is only available in update and delete triggers. |
size | The total number of records in a trigger invocation, both old and new. |
Custom Controller & Controller Extension
A custom controller is an Apex class that implements all of the logic for a page without leveraging a standard controller. Use custom controllers when you want your Visualforce page to run entirely in system mode, which does not enforce the permissions and field-level security of the current user.
A controller extension is an Apex class that extends the functionality of a standard or custom controller. Use controller extensions when:
You want to leverage the built-in functionality of a standard controller but override one or more actions, such as edit, view, save, or delete.
You want to add new actions.
You want to build a Visualforce page that respects user permissions. Although a controller extension class executes in system mode, if a controller extension extends a standard controller, the logic from the standard controller does not execute in system mode. Instead, it **executes in user mode
**, in which permissions, field-level security, and sharing rules of the current user apply.
Custom Exception:
To create your custom exception class, extend the built-in Exception class and make sure your class name ends with the word Exception.
Success message
For Create a Record, Update a Record, and Log a Call action types, you can create a custom message that displays when the action executes successfully.
Interface
Interface methods have no access modifiers. They are always global. ... This is the default, and means that the method or variable is accessible only within the Apex class in which it is defined. If you do not specify an access modifier, the method or variable is private .
StandardController
You can instantiate a StandardController in the following way:
ApexPages.StandardController sc = new ApexPages.StandardController(sObject);
StandardController Methods
The following are methods for StandardController. All are instance methods.
-
addFields(fieldNames)
When a Visualforce page is loaded, the fields accessible to the page are based on the fields referenced in the Visualforce mark up. This method adds a reference to each field specified in fieldNames so that the controller can explicitly access those fields as well. -
cancel()
Returns the PageReference of the cancel page. -
delete()
Deletes record and returns the PageReference of the delete page. -
edit()
Returns the PageReference of the standard edit page. -
getId()
Returns the ID of the record that is currently in context, based on the value of the id query string parameter in the Visualforce page URL. -
getRecord()
Returns the record that is currently in context, based on the value of the id query string parameter in the Visualforce page URL. -
reset()
Forces the controller to reacquire access to newly referenced fields. Any changes made to the record prior to this method call are discarded. -
save()
Saves changes and returns the updated PageReference. -
view()
Returns the PageReference object of the standard detail page.
Overriding Buttons, Links, and Tabs with Visualforce
You can override the behavior of standard buttons—like New, View, or Edit—in Salesforce Classic, Lightning Experience, and mobile independently. You can also override the tab home page that displays when a user clicks a standard, custom, or external object tab.
To override a standard button or a tab home page:
- Click Edit next to the button or tab home page you want to override.
- Pick Visualforce page as an override type.
Select the Visualforce page you want to run when users click the button or tab. - When overriding buttons with a Visualforce page, you must use the standard controller for the object on which the button appears.
- Use a controller extension when you need to add extra functionality to Visualforce page that you are using as an override.
- Save
Setter Method
Setter methods pass user-specified values from page markup to a controller. Any setter methods in a controller are automatically executed before any action methods.
While a getter method is always required to access values from a controller, it’s not always necessary to include a setter method to pass values into a controller. If a Visualforce component is bound to an sObject that is stored in a controller, the sObject's fields are automatically set if changed by the user, as long as the sObject is saved or updated by a corresponding action method.