Salesforce Apex Interview Questions
Salesforce Apex Interview Questions
1) What is Apex?
A) It has a Java-like syntax and is like a database stored procedure. It enables developers to add
business logic to most system events, including button clicks, related record updates, and
Visualforce pages.
A) Apex is a strongly typed language. It uses direct reference to architectural objects such as
sObject, and any invalid references that fail if they are deleted or if they are of the wrong data
type will fail quickly.
A) Apex provides built-in support for unit test creation and execution, including test results
indicating how much code is covered, and which parts of the code can be more efficient.
A) Apex should be used when we can’t use pre-built and existing out-of-the-box functionality to
implement complex business functions.
Date: addDays()/dayOfYear()/daysBetween()/month()/toStartOfMonth()/year()
Datetime: addHours()/hourGmt()/minute()
String:
compareTo()/contains()/equals()/indexOf()/length()/split()/substring()/toUpperCase()/t
oLowerCase()
Enum: ordinal()View location
sObject: addError(), parent object_r
List (ordered):
add()/remove()/clear()/clone()/deepClone()/get/set/isEmpty()/size()/sort()
Set (unordered, not repeated):
add()/addAll()/clear()/clone()contains()/cnstainsAll()/isEmpty()/remove/removeAll()/r
etainAll()/size()
Map(key-value):
clear()/clone()/deepClone()/constiansKey()/get/set/isEmpty()/keySet()/put/putAll/rem
ove/size/values
A) Apex limitations
The Apex programming language is saved and runs in the cloud – the Force.com multi-tenant
platform. Apex is tailored to data access and data manipulation on the platform, allowing you to
add custom business logic to system events. While it provides many benefits for business process
automation on the platform, it is not a general-purpose programming language.
Therefore, Apex cannot be used for:
A) Like java, Apex must end with a semicolon; it can be one of the following types:
1. Lists (arrays)
2. Maps
3. Sets
13) How can you declare List/Map/Set in Apex?
A) Apex is similar to Java’s List/Map/Set declaration method, except that it allows direct
assignment when declaring:
14) What are the different types of Apex code development tools?
A) In all versions, we can use the following three tools to develop code:
A) The Developer Console is an integrated development environment with a set of tools for
creating, debugging, and testing applications in your Salesforce organization.
A) This is a special data type in Salesforce. It is similar to a table in SQL and contains fields
similar to those in SQL. There are two types of sObjects: Standard and Custom.
17) Can you write simple example code for sObject in Apex?
System.debug(‘value objCustomer’+objCustomer);
A) An enumeration is an abstract data type that stores a value of a finite set of specified
identifiers. You can define an enumeration using the keyword Enum. Enumerations can be used
as any other data type in Salesforce.
19) Can you write sample example code for enumeration in Apex?
Assuming you want to declare the possible name of the compound, then you can do this:
DML statement: Some updates are not allowed. For example, if there are 20 records in the list,
all records will be updated or not updated.
Database method: Allow partial updates. You can specify the parameter to true or false in the
Database method, true to allow partial updates, false to not allow the same.
DML statement: You cannot get a list of success and failure records.
Database method: You can get a list of success and failure records, as we saw in the examples.
Database Method Example: Database.insert(listName, False), where false means partial updates
are not allowed.
A) SOSL:
Searching for text strings across entire objects and fields will be done using SOSL. This is the
Salesforce object search language. It has the ability to search for specific strings on multiple
objects.
The SOSL statement evaluates a list of sObjects, each of which contains search results for a
particular sObject type. The result list is always returned in the same order as specified in the
SOSL query.
SOQL:
This is almost the same as SOQL. You can use it to get only one object record from an object.
You can write a nested query and get the record from the parent or child object you want to
query.
A) The Apex call refers to the process of executing the Apex class. The Apex class can only be
executed when called by one of the following methods:
A) Apex triggers are similar to stored procedures that are executed when a specific event occurs.
It is executed before and after the event is logged.
A) Batch Apex is asynchronously executed Apex code designed to handle large numbers of
records and has more flexibility in terms of regulator limits than synchronous code.
A) When you want to process a large number of records every day, or at specific intervals, you
can go to Batch Apex.
Also, when you want an operation to be asynchronous, you can implement batch processing.
Batch Apex is exposed as an interface that must be implemented by the developer. Batch jobs
can be called programmatically at runtime using Apex. Batch Apex operates on small batch
records, overwriting the entire recordset, and breaking the process down into manageable blocks
of data.
A) In Apex, we have some tools for debugging. One of them is the system.debug() method,
which prints the value and output of the variable in the debug log.
Developer console
Debug log
A) This tool is used for script deployment. You must download the Force.com migration tool and
then you can perform a file-based deployment. You can download the Force.com migration tool
and then perform a script deployment.
Syntax:
or:
A) Blob: Binary storage type, generally used to receive uploaded attachment documents, etc.
A) ID: This type is unique to Salesforce and is used to represent the 18-bit id identifier of
salesforce’s sObject.
Integer.valueOf(’12’); //12;
E.g:
str1.contains(str2); //true
34) Can you explain some string methods which were used in your projects?
9) indexOf()- which gets the index of the first match of the string with the given string, and -1 if
there is no match.
10) lastIndexOf()- which gets the subscript of the last match of the string with the given string,
and no.
11) substring()- intercepts the string between the given subscripts in the string.
35) Can you explain about few commonly used date type methods?
A) Date and DateTime methods are many, I will mention a few commonly used methods here,
E.g:
E.g:
Date d = Date.newInstance(2018,9,12);
d.day(); //12
E.g:
Date d = Date.newInstance(2018,9,12);
d.month(); //9
E.g:
Date d = Date.newInstance(2019,9,12);
d.year(); //2019
E.g:
startDay.daysBetween(endDay); //20
E.g:
Date d = Date.newInstance(2018,9,12);
d.addDay(3); //2018-9-15
7) getTime(), which is the number of milliseconds elapsed from 1970-01-01 00:00:00 to the
calculation time.
E.g:
DateTime d = Date.newInstance(2018,9,12,8,0,0);
d.getTime(); //1473681600000
1) Integration
Insert, update and delete, etc., are included in the DmlException, called in the DML
language.
The return is sObject type recode list, tandem Salesforce Oject Query Language
(SOQL) and Salesforce Object Search Language (SOSL) query
Multiple records can be processed simultaneously
Encounter repeated data updates automatically avoid, and lock
The saved Apex method can be rebuilt, and can call the generic Force.com API
The referenced Apex custom object or custom project will be warned when it is
edited or deleted.
Apex’s variables and syntax components, modules, conditional declarations, loop declarations,
representations of objects and arrays are all based on JAVA. Considering that Apex is easier to
understand when importing new features, the Force.com platform can run more efficiently and
develop Apex.
3) Data pointing
And developers in the database server in the same essentials conduct multiple transactions
declared by the database stored procedure, on the Force.com platform server, Apex multiple
queries and DML statements are designed to a session. As with other database stored procedures,
Apex does not support execution on the user interface.
4) Very clear
The object name and project name in Apex are directly referenced to the schema object and are
strongly typed languages. When this reference is not available when the reference is not found, a
compilation error will occur immediately. In order to prevent the referenced Apex code from
being deleted, all the standard items in the master data and the class associations are saved.
5) Autonomy
The Apex language is based on the implementation, control and control of the Force.com
platform.
6) Multi-tenancy
In Apex, the upgrade of other parts of the Force.com platform does not need to be directly
described. Because the compiled code is saved as master data in the platform, Apex has also
been upgraded as part of the release.
8) Easy to test
In Apex, how much is the code covered, is it more effective than a certain part of the code? They
are all expressed in the test results, etc., and can be tested and executed as a single unit. In
SalesForce, all of the individual tests were performed before the platform upgrade, and it was
confirmed that all standard Apex code was executed as expected.
Web service
Create a mail service
Detect multiple complex objects
Create complex business processes that are not supported in workflow
Make a custom transaction (not just a single record, object, the logic of the
transaction)
2) Visualforce
Visualforce uses a tag-based tagging language that allows developers to develop user interfaces
while developing efficient ones. With VisualForce, you can do the following
Navigation patterns and inherent rule definitions for the most appropriate and effective
application interaction.
For details, please refer to the book “VisualForce Handwriting” on the SalesForce website.
3) SOAP API
The need to manage only one record type at a time, managing transactions (savepoint settings
and rollback of changes, etc.) does not use the standard SOAP API call without adding
functionality to the composite application.
A) Apex is compiled, saved and executed on the Force.com cloud platform. When the developer
saves the Apex code, the application server of the cloud platform translates the abstract
command settings into assembly code that can be recognized by the background according to the
Apex real-time translator, and then saves the commands as a metadata to the cloud platform.
The end user clicks the button and accesses the VisualForce screen to execute the Apex code.
The application server of the cloud platform obtains the compiled command from the metadata,
passes it to the cloud through the real-time program translator, and then returns the running
result. The end user does not have to care about the requirements of the cloud platform and the
difference in program execution time.