I. Programmatic features Flashcards
What is the difference between a standard controller and a custom controller?
Standard controller in Apex, inherits all the standard object properties and standard button functionality directly. It contains the same functionality and logic that are used for standard Salesforce pages.
Custom controller is an Apex class that implements all of the logic for a page without leveraging a standard controller. Custom Controllers are associated with Visualforce pages through the controller attribute.
How can we implement pagination in Visualforce?
To control the number of records displayed on each page, we use pagination. By default, a list controller returns 20 records on the page. To customize it, we can use a controller extension to set the pageSize. Take a look at the sample code below:
{!a.name}
Previous
Next
How can you call a controller method from JavaScript?
To call a controller method (Apex function) from JavaScript, you need to use actionfunction.
Look at the below piece of code to understand how a controller method is called using actionfunction.
function JSmethodCallFromAnyAction() { callfromJS(); }
How to get the UserID of all the currently logged in users using Apex code?
You can get the ID’s of all the currently logged in users by using this global function: UserInfo.getUserId().
How many records can a select query return? How many records can a SOSL query return?
The Governor Limits enforces the following:-
Maximum number of records that can be retrieved by SOQL command: 50,000.
Maximum number of records that can be retrieved by SOSL command: 2,000.
What is an attribute tag? What is the syntax for including them?
An attribute tag is a definition of an attribute of a custom component and it can only be a child of a component tag.
Note that you cannot define attributes with names like id or rendered. These attributes are automatically created for all custom component definitions. The below piece of code shows the syntax for including them:
<p> </p> <p> </p> <p> </p> <h1 style="">
</h1> <p> </p> <p> </p> <p> </p> <p>
</p>
What are the three types of bindings used in Visualforce? What does each refer to?
There are three types of bindings used in Salesforce:-
Data bindings, which refer to the data set in the controller
Action bindings, which refer to action methods in the controller
Component bindings, which refer to other Visualforce components.
Data bindings and Action bindings are the most common and they will be used in every Visualforce page.
What are the different types of collections in Apex? What are maps in Apex?
Collections are the type of variables which can be used to store multiple number of records (data).
It is useful because Governor Limits restrict the number of records you can retrieve per transaction. Hence, collections can be used to store multiple records in a single variable defined as type collection and by retrieving data in the form of collections, Governor Limits will be in check. Collections are similar to how arrays work.
There are 3 collection types in Salesforce:
Lists Maps Sets Maps are used to store data in the form of key-value pairs, where each unique key maps to a single value. Syntax: Map country_city = new Map();
How can you embed a Visualflow in a Visualforce page?
- Find the flow’s unique name.
a. From Setup, enter Flows in the Quick Find box, then select Flows.
b. Click the name of the flow.
c. Copy the unique name of the flow. - From Setup, enter Visualforce Pages in the Quick Find box, then select Visualforce Pages.
- Define a new Visualforce page, or open an existing one.
- Add the component somewhere between the tags.
- Set the name attribute to the unique name of the flow.
For example:
- Click Save.
- Restrict which users can access the Visualforce page.
a. Click Visualforce Pages.
b. Click Security next to your Visualforce page.
c. Move all the appropriate profiles from Available Profiles to Enabled Profiles by using the ‘add’ and ‘remove’ buttons.
d. Click Save. - Add the Visualforce page to your Force.com app by using a custom button, link, or Visualforce tab.
What is the use of “@future” annotation?
Future annotations are used to identify and execute methods asynchronously. If the method is annotated with “@future”, then it will be executed only when Salesforce has the available resources.
For example, you can use it while making an asynchronous web service callout to an external service. Whereas without using the annotation, the web service callout is made from the same thread that is executing the Apex code, and no additional processing will occur until that callout is complete (synchronous processing).
What are the different methods of batch Apex class?
Database.Batchable interface contains three methods that must be implemented:
Start method:
global (Database.QueryLocator | Iterable) start(Database.BatchableContext bc) {}
Execute method:
global void execute(Database.BatchableContext BC, list<p>){}
Finish method:
global void finish(Database.BatchableContext BC){}</p>
What is a Visualforce component?
A Visualforce Component is either a predefined component (standard from component library) or a custom component that determines the user interface behavior. For example, if you want to send the text captured from the Visualforce page to an object in Salesforce, then you need to make use of Visualforce components. Example:
What is Trigger.new?
Trigger.new is a command which returns the list of records that have been added recently to the sObjects. To be more precise, those records will be returned which are yet to be saved to the database. Note that this sObject list is only available in insert and update triggers, and the records can only be modified in before triggers.
But just for your information, Trigger.old returns a list of the old versions of the sObject records. Note that this sObject list is only available in update and delete triggers.
What all data types can a set store?
Sets can have any of the following data types:
- Primitive types
- Collections
- sObjects
- User-defined types
- Built-in Apex types
What is an sObject type?
An sObject is any object that can be stored in the Force.com platform database. Apex allows the use of generic sObject abstract type to represent any object.
For example, Vehicle is a generic type and Car, Motor Bike all are concrete types of Vehicle.
In SFDC, sObject is generic and Account, Opportunity, CustomObject__c are its concrete type.