Salesforce Interview Question

 

Debug & Deployment Tools – Salesforce Interview Questions

 What are the different ways of deployment in Salesforce?

You can deploy code in Salesforce using:

  1. Change Sets
  2. Eclipse with Force.com IDE
  3. Force.com Migration Tool – ANT/Java based
  4. Salesforce Package

H. Integration – Salesforce Interview Questions

 What is an external ID in Salesforce? Which all field data types can be used as external IDs?

An external ID is a custom field which can be used as a unique identifier in a record. External IDs are mainly used while importing records/ data. When importing records, one among the many fields in those records need to be marked as an external ID (unique identifier).

An important point to note is that only custom fields can be used as External IDs. The fields that can be marked as external IDs are: TextNumberE-Mail and Auto-Number.

How many callouts to external service can be made in a single Apex transaction?

Governor limits will restrict a single Apex transaction to make a maximum of 100 callouts to an HTTP request or an API call.

How can you expose an Apex class as a REST WebService in Salesforce?

You can expose your Apex class and methods so that external applications can access your code and your application through the REST architecture. This is done by defining your Apex class with the @RestResource annotation to expose it as a REST resource. You can then use global classes and a WebService callback method.

Invoking a custom Apex REST Web service method always uses system context. Consequently, the current user’s credentials are not used, and any user who has access to these methods can use their full power, regardless of permissions, field-level security, or sharing rules.

Developers who expose methods using the Apex REST annotations should therefore take care that they are not inadvertently exposing any sensitive data. Look at the below piece of code for instance:-

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
global class AccountPlan {
 webservice String area;
 webservice String region;
 //Define an object in apex that is exposed in apex web service
 global class Plan {
 webservice String name;
 webservice Integer planNumber;
 webservice Date planningPeriod;
 webservice Id planId;
 }
 webservice static Plan createAccountPlan(Plan vPlan) {
 //A plan maps to the Account object in salesforce.com.
 //So need to map the Plan class object to Account standard object
 Account acct = new Account();
 acct.Name = vPlan.name;
 acct.AccountNumber = String.valueOf(vPlan.planNumber);
 insert acct;
 vPlan.planId=acct.Id;
 return vPlan;
 } }

I. Programmatic Features – Salesforce Interview Questions

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:-

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
<apex:page standardController="Account" recordSetvar="accounts">
 <apex:pageBlock title="Viewing Accounts">
 <apex:form id="theForm">
 <apex:pageBlockSection >
 <apex:dataList var="a" value="{!accounts}" type="1">
 {!a.name}
 </apex:dataList>
 </apex:pageBlockSection>
 <apex:panelGrid columns="2">
 <apex:commandLink action="{!previous}">Previous</apex:commandlink>
 <apex:commandLink action="{!next}">Next</apex:commandlink>
 </apex:panelGrid>
 </apex:form>
 </apex:pageBlock>
</apex:page>

 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.

1
2
3
4
5
6
<script>
function JSmethodCallFromAnyAction()
{
callfromJS();
}
</apex:page>

 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:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
<apex:component>
 <apex:attribute name="myValue" description="This is the value for the component." type="String" required="true"/>
 <apex:attribute name="borderColor" description="This is color for the border." type="String" required="true"/>
  
</p>
<p>
</p>
<p>
</p>
<p>
</p>
<h1 style="border:{!borderColor}">
 <apex:outputText value="{!myValue}"/>
 </h1>
<p>
</p>
<p>
</p>
<p>
</p>
<p>
 
</apex:component>

 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<String, String> country_city = new Map<String, String>();

 How can you embed a Visualflow in a Visualforce page?

  1. Find the flow’s unique name.

    1. From Setup, enter Flows in the Quick Find box, then select Flows.
    2. Click the name of the flow.
    3. Copy the unique name of the flow.
  2. From Setup, enter Visualforce Pages in the Quick Find box, then select Visualforce Pages.

  3. Define a new Visualforce page, or open an existing one.

  4. Add the <flow:interview> component somewhere between the <apex:page> tags.

  5. Set the name attribute to the unique name of the flow.

For example:

1
2
3
</apex:page>
<flow:interview name="flowuniquename"/>
<apex:page>
  1. Click Save.

  2. Restrict which users can access the Visualforce page.

    1. Click Visualforce Pages.
    2. Click Security next to your Visualforce page.
    3. Move all the appropriate profiles from Available Profiles to Enabled Profiles by using the ‘add’ and ‘remove’ buttons.
    4. Click Save.
  3. 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:

  1. Start method:
    global (Database.QueryLocator | Iterable<sObject>) start(Database.BatchableContext bc) {}
  2. Execute method:
    global void execute(Database.BatchableContext BC, list<P>){}
  3. Finish method:
    global void finish(Database.BatchableContext BC){}

 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: <apex:detail>

 What is Trigger.new?

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

 What is the difference between SOQL and SOSL?

The differences are mentioned in the table below:

SOQL vs SOSL

SOQL (Salesforce Object Query Language)SOSL (Salesforce Object Search Language)
Only one object can be searched at a timeMany objects can be searched at a time
Can query any type of fieldCan query only on email, text or phone
Can be used in classes and triggersCan be used in classes, but not triggers
DML Operation can be performed on query resultsDML Operation cannot be performed on search results
Returns recordsReturns fields

 What is an Apex transaction?

An Apex transaction represents a set of operations that are executed as a single unit. The operations here include the DML operations which are responsible for querying records. All the DML operations in a transaction either complete successfully, or if an error occurs even in saving a single record, then the entire transaction is rolled back.

 What is the difference between public and global class in Apex?

Global class is accessible across the Salesforce instance irrespective of namespaces.
Whereas, public classes are accessible only in the corresponding namespaces.

 What are getter methods and setter methods?

Get (getter) method is used to pass values from the controller to the VF page.
Whereas, the set (setter) method is used to set the value back to controller variable.

Comments

Popular posts from this blog

General Interview Questions and Answers

20 Performance Testing Interview Questions and Answers

Leadership: a Definition