Previously Visualforce Pages were not there, instead S-Controls were there. S-controls have been superseded by Visualforce pages. Organizations that haven’t previously used s-controls can’t create them. Existing s-controls are unaffected, and can still be edited.
S-controls: It is a combination of HTML and S-control but with this to achieve saelsforce look and feel, it is very difficult and consume lot of tags. Visualforce: With visualforce we can easily achieve the salesforce look and feel by consuming very few tags.
Browsers (IE, Chrome, Firefox, etc…) can understand only HTML, Visualforce will be converted to HTML before display on the browser by salesforce.
System Mode: Current logged in user permissions (Object-level, Field-level, Record-level security) won’t be considered. Even though user doesn’t has access, it will provide full permissions. User Mode: Current logged in user permissions (Object-level, Field-level, Record-level security) will be considered.
See the following table –
Component – Default Mode
Apex Class – System Mode
Apex Trigger – System Mode
standardController – User Mode
controller – System Mode
Extensions (standardController) – User Mode
Extensions (controller) – System Mode
Anonymous Block – User Mode
Note: to apply security for Apex Class, we can use with sharing while declaring the class. With sharing will apply only Record-level security. It won’t apply Object-level and Field-level security.
There are the two types of controllers –
Note: On a visualforce page, we can use either standardController (attribute name for Standard Controller) or controller (attribute name for Custom Controller). We cannot refer both at a time.
StandardController –
We can refer any standard object or custom object in this attribute. At a time we can refer only one object and we cannot refer apex class in this attribute. standardController by default works in user mode.
Custom Controller –
We can refer any apex class in this attribute. At a time we can refer only one apex class in this attribute. Controller by default works in system mode. Other supported attributes for the controllers –
Extensions
Standard List Controller
Custom List Controller
Extensions –
We can refer this attribute along with standardController or controller attribute. In extensions attribute, we can refer multiple apex classes. We cannot refer standard/custom objects.
Standard List Controller –
There is no such attribute called standard list controller but in the standardController page if you mention recordsetVar attribute then that page we can call it as standard list controller page.
In recordsetVar attribute we can give any name which will hold the list of records of the object which we mentioned for the standardController.
Custom List Controller –
There is no such attribute called custom list controller but in the controller page if we display multiple records then that page we can call it as custom list controller. In controller class, we have to query the records from the database to display the records on the page.
controller=”MainClass”
extensions=”ClassA,ClassB,ClassC”
click to see the question in detail. A method with the name save exists in all the classes mentioned above. Which will execute first and what is the order?First of all it will give priority for the extensions, in case there are multiple classes referred then it will give priority from left to right after that only it will check in main controller (either standardController or controller).
In the above scenario, it will invoke the save method from ClassA.
Creation: In a visualforce page, whenever we use form tag then view state will be created for the page.
Purpose: Assume that, we need to display the user input form in 3 different visualforce pages. In first and second pages, user has to fill the information and click on Next button. On the final page, after filling the form if he/she will click on save button, whichever the information we filled in the first and second pages should be also saved. View state will store the information which is filled in first and second page. To maintain the state of the page, we need view state.
Size: All the variables which we use in controller/extensions classes and expressions which are declared on the page will occupy the space in view state. Governor Limits: Maximum size of the View State is: 135 KB.
Page Performance: Whatever the variables information we don’t required to maintain the state while navigating to other pages those variables we can decorate with transient keyword which won’t occupy space in the view state.
It is recommended to use only one form tag. If there are multiple form tags hierarchy of the folder structure increases which will occupy more space.
To store the following kind of files and refer on the visualforce page –
Overall size of the static resources per organization: 250 MB
Size of the each static resource file: 5 MB
To refer the static resource on the VF page use: $Resource.FileName
To refer the zipped static resource on the VF page use: URLFOR($Resource.zipname, ‘/images/FileName.png’)
Please find the following differences – Static Resources Documents Static Resource is cached at server side Documents will store in database Static Resources can be referred with file name Documents should be referred with url
On VF page we should use –
<apex:pageMessages ></apex:pageMessages>
In Apex Class, we should use –
ApexPages.addMessage(new ApexPages.Message(ApexPages.severity.Error,’Error Message’));
Note: For the standardController no need to include code inside of the Apex Class.
Following severity levels are available –
On a standardController page to display the multiple records we use recordSetVar (without the support of any extensions class).
dataTable: Display the records without standard salesforce look and feel. pageBlockTable: Display the records with standard salesforce look and feel.
1000
For the page tag we can enable readOnly attribute value as true so that – Number of query rows will increased from 50000 to 1 million rows. Number of records displayed on VF page can be increased from 1000 to 10000
inputText: Always display the field as text box irrespective of data types (Checkbox, Picklsit, Look up).
inputField: Display automatically according to the fields data types. Note: We cannot refer primitive data types (String etc.) with inputField.
outputText: Always display the field value as text irrespective of data types (Currency, Look up, URL etc.)
outputField: Display automatically according to the fields data types. If it is currency then it will append currency symbol while displaying on the page. If it is look up type then it will display as a link.
Assume that we need to display 100 records on the page.
If the requirement is to display only 10 records at a time –
First: Displays first set of 10 records.
Previous: Displays previous set of 10 records.
Next: Displays next set of 10 records.
Last: Displays last set of 10 records.
We can achieve the above functionality with Pagination. We can achieve the pagination in two ways –
Wrapper Class is nothing but list of instances of a certain class.
Follow the below steps to create the Wrapper list –
Create an Apex Class say ‘MyWrapper'
(It can be inside/outside of the controller class.)
Declare the necessary variables in the class to store the information.
Create a list called ‘MyWrapList’
for ‘MyWrapper’
.
Create multiple instances for‘MyWrapper’
and store it in ‘MyWrapList’
list.
Access ‘MyWrapList’
list from VF page.
In the below scenarios, we have to go for wrapper class –
If you want to display checkboxes along with records so that upon selecting checkboxes corresponding records can be processed (Updating, Deleting, etc.). If you need to display records in single table by combining the columns which belongs to multiple objects
What is the advantage? Assume that you are referring a Record Type Name multiple times in an apex class; in future if the client asked to rename the record type then in all the palaces we need change by searching which consume good amount of time.
To avoid that if you store the Record Type Name in custom label and refer that custom label in all the places.
If you need to change the name in future then you need to change only in that custom label.
Assume that you are displaying an error message on the visualforce page; in future if the client asked to change the error message then it will be a code change.
For code change it requires lot of approvals from business which consume lot of time. If you keep the error message in a custom label and refer on the page, in future it won’t be a code change, in production directly they can replace the error message in that custom label.
There are two types of custom settings –
We can create the fields and we can store the records.
List Custom Settings records will store in Application Cache memory.
To access List Custom Settings records no need to use SOQL query.
Example: Based on the regions, zip codes should be retrieved. In this case, If you store these records in a custom object every time we need to query from the database. Instead if you store the records in List Custom Settings, without consuming SOQL query we can capture the information from the database.
Hierarchy custom settings:
We can add users and profiles.
After that we can check that a particular/current logged in user is part of this custom settings.
We can refer this in below components –
Custom Settings Custom Objects
rendered: Accepts true or false. If it is true then component will display on the page, if it is false then it won’t display on the page.
reRender: To refresh certain area of a page based on component id.
renderAs: Used in page tag, We can display VF page in PDF format if we give renderAs = “PDF”.
contentType: Used in page tag, we can download VF page in MS Word/Excel etc. based on the input to contentType.
We can override the behavior of standard buttons — like New, View, or Edit — in Salesforce Classic, Lightning Experience, and mobile independently.
We can override few standard buttons with visualforce pages.
To override standard button with visualforce page, VF page should use standardController to an object which is related to standard button.
Custom buttons we can override with URL, javaScript or Visualforce.
On a record detail page we can embed visualforce pages. Assume that you are displaying inline VF page on Account record detail page. VF page should be standardCotnroller to Account Object.
Note: We cannot embed VF page inside of the Edit page.
Whenever we click on Back or Cancel button on a VF page if there are mandatory fields then we will see the error messages saying to populate those field values. To bypass validations upon clicking on a button/link, we can use immediate attribute.
Parameters Example: /apex/SamplePage?param1=val1¶m2=val2
?param1=val1 – parameters should start with ? symbol
¶m2=val2 – To add multiple parameters, each parameter should be separated with & symbol.
Ways of passing parameters –
From a VF Page: Whenever we click on commandButtton or commandLink or outputLink, we can pass parameters with param tag.
See the below example –
<apex:commandButton action=”{!Increment}” value=”Increment” reRender=”result”>
<apex:param assignTo=”{!amount}” value=”10″/>
</apex:commandButton>
From pageReference: Upon calling an action method while returning pageReference we can append parameters.
See the below example –
PageReference nextpage = new PageReference(‘/apex/SamplePage’);
nextpage.getParameters().put(‘param1′,’val1’);
nextpage.getParameters().put(‘param2′,’val2’);
Salesforce provides a library of standard, pre-built components, such as <apex:relatedList> and <apex:dataTable>, that can be used to develop Visualforce pages. In addition, you can build your own custom components to augment this library. Similar to the way you can encapsulate a piece of code in a method and then reuse that method several times in a program, you can encapsulate a common design pattern in a custom component and then reuse that component several times in one or more Visualforce pages.
<apex:component>
<apex:attribute name=”myattribute” type=”String” description=”TODO: Describe me”/>
<!– Begin Default Content REMOVE THIS –>
<h1>Congratulations</h1>
This is your new Component: mynewcomponent
<!– End Default Content REMOVE THIS –>
</apex:component>
If you want to reuse the VF page logic, then we can use VF Components. If the VF page logic is huge and if you want to split into different pieces, then we can use VF Components.
We can request VF page in two ways –
Get Request: Whenever we click on a link or button or directly hitting the url in address bar we can open a VF page. Get Request Order
Postback Request: On a VF page after populating fields if you click on save button certain action will invoke it is nothing but postback request. Postback Request Order
There are around 5 AJAX functions –
<apex:actionRegion>
are processed by the server, thereby increasing the performance of the page.