1. What is visualforce controllers and what are they?
A Visualforce controller is a set of instructions that specify what happens when a user interacts with the components specified in associated Visualforce markup, such as when a user clicks a button or link.
There are two types of controllers-
1. Standard Controller
2. Custom Controller
2. What is the diffrence between standard controller and custom controller?
StandardController: Which already have a Standard functionalities (save, edit, delete,cancel), and passing recordID through Addressbar we can display the Record On VF-Page.
CustomController: it means we are going to implement our Controller methods in a Class using {get;set;} methods.
3. What is the difference between custom controller and 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.
4. What is the difference between system mode(system context) and user mode(user context)?
System mode -
1. System mode is nothing but running apex code by ignoring user's permissions. For example, logged in user does not have to create permission but he/she is able to create a record.
2. In system mode, Apex code has access to all objects and fields— object permissions, field-level security, sharing rules aren't applied to the current user. This is to ensure that code won’t fail to run because of hidden fields or objects for a user.
3. In Salesforce, all apex code run in system mode. It ignores user's permissions. The only exception is anonymous blocks like developer console and standard controllers. Even runAs() method doesn't enforce user permissions or field-level permissions, it only enforces record sharing.
User mode -
1. User mode is nothing but running apex code by respecting user's permissions and sharing of records. For example, logged in user does not have to create permission and so he/she is not able to create a record.
2. In Salesforce, only standard controllers and anonymous blocks like developer console run in user mode.
5. How to display error messages on VF(Visualforce) page?
On apex class we need a following code line-
ApexPages.addmessage(new ApexPages.message(ApexPages.severity.Error,'This is error message'));
we have following 5 severity levels available in salesforce-
1. CONFIRM
2. ERROR
3. FATAL
4. INFO
5. WARNING
And on Visualforce page we need a following tag-
apex:pageMessages or apex:pageMessage
6. What are expressions used in pages to bind in controllers?
Using methods we can bind.
Getter:Will return value from controller to vf page
Setter:Will pass value from vf page to controller
Action:Will redirect to another page.
7. Which objects have associated standard controllers?
All standard and custom objects that can be accessed via the API have associated controllers.
8. What is included with each standard controller?
Data: the fields for the associated object record that are API accessible, including the related records (5 up/1 down).
Actions: save, delete, view, edit, cancel.
9. Compare and contrast custom controllers and controller extensions. How are they the same? How are they different?
Both allow for custom code to be used, allowing for custom data sets and custom actions. Extensions leverage the existing data and actions within a standard or custom controller. Custom controllers must contain all data and actions that need to be executed by the page. Extensions that extend standard controller allow for the pages which use those extensions to be used in custom buttons, standard button overrides, and over declarative features.
10. In what order do methods fire within a controller?
The only rule is that setters fire before action methods. Aside from that, there is no guaranteed order.
11. Is it always necessary to know apex to create visualforce pages? When does it become necessary?
No, it is not always necessary. You can use standard controllers and VF component tags to accomplish quite a bit.
Apex becomes necessary when you need either a custom set of data or custom actions to be available from the page.
12. What is the main difference between using Data Table Vs. Page Block Table tags?
Page Block Table: Display the records with standard salesforce look and feel.
Data Table: Display the records without standard salesforce look and feel.
13. Which tag is used with both radio buttons and picklists to create the selectable values?
apex:selectoption tag
14. What are some examples of javascript events?
Onmouseover, onclick etc.
15. What are the different ajax action tags? What does each do?
actionStatus: used to display start and stop statuses of AJAX requests.
actionSupport: used to call a second component when an event happens to the first component.
actionPoller: similar to actionSupport, but the event is based on a timer instead of a user action.
actionFunction: provides support for invoking a controller action from JavaScript code using an AJAX request by defining a new JavaScript function.
actionRegion: used to demarcate which parts of the page the server should reprocess.
16. How to make pick-list as required (thru java script)?
We have to create custom button and in that custom button we have to write Java script code to check whether the picklist value is null.
17. Is there any alternative for the "ActionPoller"?
Using SetTimeout in Javascript and calling the apex method using apex:actionFunction.
18. What is the difference between apex:pageMessages, apex:pageMessage, apex:Message and apex:Messages?
apex:PageMessages:
This component displays all messages that were generated for all components on the current page, presented using the salesforce styling. This will display both salesforce generated messages as well as custom messages added to the ApexPages class
apex:PageMessage:
Apex:PageMessage is a component that adds single message on the page. This is used to display custom message using the salesforce formatting
apex:Message:
apex:Message is used to display an error on only a specific field. It is used to allow developers to place field specific errors in specific location.
apex:Messages:
apex:Messages is similar to apex:Message but it displays all errors
19. What is view state?
Visualforce pages that contain a form component also contain an encrypted, hidden form field that encapsulates the view state of the page. This view state is automatically created, and as its name suggests, it holds the state of the page - state that includes the components, field values and controller state.
20. What does view state contains?
1. The data in the view state should be sufficient to recreate the state of the page when the postback is received. To do this, it stores the following data:
2. All non-transient data members in the associated controller (either standard or custom) and the controller extensions.
3. Objects that are reachable from a non-transient data member in a controller or controller extension.
4. The component tree for that page, which represents the page’s component structure and the associated state, which are the values applied to those components.
5. A small amount of data for Visualforce to do housekeeping.
21. How to reduce view state?
1. Add transient keyword before variables, like lists used just for printing the tables.
2. Try recreating state, by querying again the database, storing in local lists, sets or maps will not work.
3. Declare some variable as static if possible, create static code block to recreate them in each request.
4. Check your SOQL queries, if you are querying additional fields, never used or required on visualforce page.
22. Why we used transient key word?
The transient key word prevents the data from being saved into the view state. This should be used for very temporary variables.
23. What are the ways that Visualpages can be incorporated into the rest of your user interface?
Basically, via links, buttons, tabs, and inline frames.
24. What are static resources?
Static resources are a new type of storage in Salesforce specifically designed for use in Visualforce pages. They are ways to store images, flash files, stylesheets, and other web resources on the Salesforce servers that can be cached for better page performance.
25. Maximum number of records displayed on the VF page?
1000
26. How to display more records beyond the supported limit on the VF page?
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 will be increased from 1000 to 10000
27. What is the difference between inputText and inputField?
InputText: Always display the field as text box as comparision to salesforce data types like- Checkbox, Picklist, Date.
InputField: Display automatically according to the salesforce fields data types.
28. What is the difference between outputText and outputField?
OutputText: Always display the field value as text as comparision to salesforce data types like- Checkbox, Picklist, Date.
OutputField: Display automatically according to the salesforce fields data types.
29. What is pagination and what are the ways to achieve it?
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 pagination in two ways-
Using standardSetController
Using Limit and Offset keywords in SOQL query.
30. What is the difference between rendered, rerender, renderAs and contentType?
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.
31. What is the use of immediate attribute?
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.
32. What are the Visualforce Components? When to use VF Component?
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 visualforce component and then reuse that component several times in one or more Visualforce pages.
Uses of VF Component-
1. If you want to reuse the VF page logic.
2. If the VF page logic is huge and if you want to split into different pieces.
33. What is remote action?
Remote action function in salesforce allows user to access any method from any class through javasrcipt methods, and get the result as a javascript object for further manipulation. Points to remember while implementing remote action function: Remote action method should have @RemoteAction annotation.
34. What is AJAX? Where you have used?
AJAX stands for Asynchronous JavaScript and XML. AJAX is a new technique for creating better, faster, and more interactive web applications with the help of XML, HTML, CSS, and Java Script.
Update a web page without reloading the page
Request data from a server - after the page has loaded
Receive data from a server - after the page has loaded
Send data to a server - in the background
35. What is jQuery? Where you have used?
jQuery is a popular open-source JavaScript framework that Web developers use to solve basic app development problems across all browsers while opening the code to the public for community-driven development and support. jQuery's design lets developers extend the core libraries with new projects and plugins to add new features and functionality.
When you want to improves the performance of an application.
When you want to make Browser's compatible web applications can be developed.
36. How do you make a VF page available for salesforce1 and lightning experince?
To enable "Available for Lightning Experience, Lightning Communities, and the mobile app" checkbox.