Skip to main content

Salesforce Visual Force Interview Questions - 2




12. What are the Best Practices to Improve Visualforce Performance?


1) By using the with sharing keyword when creating your Apex controllers, you have the possibility of improving your SOQL queries by only viewing a data set for a single user.


2) The view state size of your Visualforce pages must be under 135 KB. By reducing your view state size, your pages can load quicker and stall less often.


3) Reduce Multiple Concurrent Requests: use <apex:actionpoller>

4) Preventing Field Values from Dropping Off the Page.

5) Large page sizes directly affect load times. To improve Visualforce page load times:
  •      Cache any data that is frequently accessed, such as icon graphics.
  •      Avoid SOQL queries in your Apex controller getter methods.
  •      Reduce the number of records displayed on a page by adding filter condition in SOQL

13.  What is the maximum size of the PDF generated on visualforce attribute renderAs?

1. Before being rendered as a PDF, the maximum response size when creating a PDF must be below 15 MB.  This is the standard limit for all Visualforce requests.

2.  The maximum file size for a generated PDF is 60 MB.

3. The total size of all images included in a generated PDF is 30 MB.


14. What is Difference in render, rerender and renderas attributes of visualforce?

render: It works like display property of CSS. It is used to show or hide element on visualforce page.

rerender: 
After Ajax which component should be refreshed – This attribute is available on commandlink, commandbutton, actionsupport.

renderas: 
render page as PDF, DOC and Excel. With the help of this attribute you can download the data display on visualforce page.

15.  What is the use of Test.setPage()?

It is used to set the context to current page, normally used for testing the visual force controller.

16. What is the difference between apex:dataTable and apex:pageBlockTable components in Visualforce?

Each component is used to render data in tabular format. apex:dataTable will render records in simple HTML table format whereas the apex:pageBlockTable possess default look and feel of salesforce standard CSS and must be written inside apex:pageBlock component.


17. What is best practice to refer dynamic custom messages in Visualforce with multi-language support?

Using Custom Label or OutputField or InputField tag, Platform itself will take care of internationalization. However, in some cases, Message needs to be dynamic at the same time it should also support muti-language. In Custom Label, we cannot save dynamic String.

Let’s assume we want to show message something like “DEVELOPERNAME is not authorized to access this page”.
Here, Developername should be dynamically changed in visualforce which supports multilanguage. For each developername, it is not feasible to create custom labels. So below workaround can be used:

Step 1 : Create a Custom Label with text  {0} is not authorized to access this page. In every language, dynamic value should represented by {0}.

Step 2 : In Controller of Visualforce write something like this :

String developerName = 'Some Developer Name';
String message = String.format(Label.DEVELOPERNAME , new String[] { developerName });

18. How to display error messages in the visualforce page?

In Apex use below code to create the error message for visualforce.
Apexpages.addMessage( new ApexPages.Message (ApexPages.Severity.ERROR, 'Required fields are missing. '));
And in Visualforce page,  add below tag where you want to display the error message which display the error message.

<apex:pageMessages > </apex:pageMessages>


19. 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

20. What are the global variables?

Global variables are represented using $ symbol, these variables can be accessed across all the Visualforce page

Example: <h1>{!$user.firstname}

Comments