Wednesday 16 January 2019

Visualforce - Part 1

1) What is View state in Visual force ?
To maintain state in a Visualforce page, the Lightning Platform platform includes the state of components, field values, and controller state in a hidden form element.
This encrypted string is the view state and has a limit of 135 KB. Large view states require longer processing times for each request, including serializing and deserializing, and encryption and decryption.
Reducing your view state size causes your pages to load quicker and stall less often.
Use the View State tab in the development mode footer to monitor view state performance, and take the following actions.
Use the transient keyword in your Apex controllers for variables that aren’t essential for maintaining state and aren’t necessary during page refreshes.
If you notice that a large percentage of your view state comes from objects used in controllers or controller extensions, consider refining your SOQL calls to return only data that's relevant to the Visualforce page.
If your view state is affected by a large component tree, try reducing the number of components your page depends on.
Use filters and pagination to reduce data requiring state.
Declare instance variables with a transient keyword when the variable is only useful for the current request. The view state includes all non-transient members in the controller and extension, as well as objects reachable from these non-transient members. Decide if some data can be read-only and use the <apex:outputText> component instead of <apex:inputField>.
Set the Development Mode and Show View State in Development Mode permissions set to see the View State tab in the development mode footer. The tab displays the distribution of view state. Make sure you know the view state size of each page, and test with large data volumes to determine if issues might occur after deployment.
Use JavaScript remoting. Unlike the <apex:actionFunction> component, JavaScript Remoting does not require a form component. This technique doesn’t reduce the overall view state of a page, but your page generally performs better without the need to transmit, serialize, and deserialize the view state. The tradeoff is the loss of the re-render attribute and the additional JavaScript code to handle callbacks.

2) Which api used to design Visual force page?
Metadata Api


3) What is difference between insert and include?
Apex:Insert
A template component that declares a named area that must be defined by an <apex:define> component in another Visualforce page.
Use this component with the <apex:composition> and <apex:define> components to share data between multiple pages.
Apex:include
A component that inserts a second Visualforce page into the current page. The entire page subtree is injected into the Visualforce DOM at the point of reference and the scope of the included page is maintained.

4) What is the difference between controller and extension ?
Custom Controller:
It is an Apex class that implements all of the logic for a page without leveraging a standard controller.
You can use only one Apex class.
You can 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.

Extension:
A controller extension is any Apex class containing a constructor that takes a single argument of type ApexPages.
It provides additional functionality to a controller – either a standard controller or a custom controller.
You can use multiple Apex classes separated by comma.
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.

5) What is the use Static Resource in Visual force?
The way you reference a static resource in Visualforce markup depends on whether you want to reference a stand-alone file, or whether you want to reference a file that is contained in an archive (such as a .zip or .jar file):
To reference a stand-alone file, use $Resource.<resource_name> as a merge field, where <resource_name> is the name

7) How do you refer to current page id
 public CurrentRecordIdDemoController(ApexPages.StandardController controller) {
        currentRecordId  = ApexPages.CurrentPage().getparameters().get('id');
        acc = [select id ,name, AccountNumber, Type, Industry from Account where id =: currentRecordId ];
        parameterValue = ApexPages.CurrentPage().getparameters().get('nameParam');
    }
}

8) What are custom components?
Yes

No comments:

Post a Comment

Batch Apex

1. What are transaction limits in apex? Total number of SOQL queries issued1 - 100 Total number of records retrieved by SOQL queries - 50...