Professional Documents
Culture Documents
Salesforce Frequently Asked Interview Questions and Answers
Salesforce Frequently Asked Interview Questions and Answers
To call Future methods from Process Builder, call the future method from the
invocable method.
3.What is System.RunAs?
Generally, all Apex code runs in system mode, where the permissions and
record sharing of the current user are not taken into account. The system
method runAs enables us to write test methods that change the user context
to an existing user or a new user so that the user’s record sharing is
enforced.
This error means that two Sobjects(setup & non-setup) that we are using in
our code can not mix during the same transactions.This restriction exists
because some sObjects affect the user’s access to records in the org.
For example, We cannot insert an account and then insert a user or a group
member in a single transaction.
1. Separate the Setup object and Non-Setup object dml operation using
Future Method.
2. System.RunAs : Enclose mixed DML operations
within System.runAs blocks to avoid the mixed DML error in test class.
Before triggers can be used to update or validate record values before they
are saved to the database.
Use Before Trigger:In the case of validation check in the same object.
Insert or update the same object.
After triggers can be used to access field values that are set by the database
(such as a record's Id or lastUpdated field) and to affect changes in other
records, such as logging into an audit table or firing asynchronous events
with a queue.Use After Trigger:Insert/Update related object, not the same
object.
Notification email.
Without Sharing
2.We want to use apex class globally for integration purspose,then we can
use without sharing.
Yes,apex class always execute in system context i.e. Apex code has access
to all objects and fields irrespective of the logged in User.
Apex Managed Sharing is used to grant the access to the records.It is about
pro grammatically configuring sharing rules. Keyword "With Sharing" is used
to respect the current user sharing rule.
14.What is database.savepoint?
• If you set more than one savepoint, then roll back to a savepoint that
is not the last savepoint you generated, the later savepoint variables
become invalid.
• References to savepoints cannot cross trigger invocations, because
each trigger invocation is a new execution context. If you declare a
savepoint as a static variable then try to use it across trigger contexts
you will receive a runtime error.
• Each savepoint you set counts against the governor limit for DML
statements.
16.What is database.rollback?
3.We can use the upsert API call with the external ID to refer to records.
23.What is TOTP?
TOTP is time-based one-time password. We can use login flow that enhances
TOTP authentication with a two-factor authentication method that Salesforce
supports. The TOTP algorithm computes a one-time password from a shared
secret key and the current time.
This annotation lets us mark an Apex method as being something that can
be called from somewhere other than Apex.
Yes we can call an apex class from process builder. To call an Apex
method, add the Call Apex action to your process and select an Apex class
with a @invocable method Annotation.
Setup objects are those which interacts with metadata All other object
(Standard and Custom) are non setup object.
Static
Non-static
Non-static method (and variables) must have a new instance of the class
instantiated in order to be used. Typically these rely on data inside the class
that then is referred to inside the class.
Keyword- Reserved word having specific meaning. The words which have
meaning already defined. We cannot use keyword to define variable.
Literal - The name which we give. Like variable name.
Apex allows you to use the private, protected, public, and global access
modifiers when defining methods and variables.
Private: The method or variable is accessible only within the Apex class in
which it is defined. Note: By default all variables are private.
Public: The method or variable can be used by any Apex in this application
or namespace.
Global: The method or variable can be used by any Apex code that has
access to the class, not just the Apex code in the same application.
36.What is Recursion ?
Recursion occurs when same code is executed again and again. It can lead
to infinite loop and which can result to governor limit sometime.
To avoid the situation of recursive call, we have to write code in such a way
that the trigger will execute one time. To do so, we can create a class with a
static Boolean variable with default value true.
38.What is With sharing and without sharing?
Example
Without Sharing:If you declare a class as a Without Sharing, then this Apex
class runs in system mode which means Apex code has access to all the
objects and field irrespective of current users sharing rules, field level
security and Object permissions.
2 – All Before Triggers are executed (BT) – Before trigger will execute and
do the manipulation.
4 – Executes duplicate rules (DR) – All duplicate rule will execute for the
Object if any
If workflow rule update any field then before and after triggers are executed
one more time if the workflow rule updates a field (BT & AT)
If process builder update any field then before and after triggers are
executed one more time if the workflow rule updates a field (BT & AT)
Note : The order of execution isn’t guaranteed when having multiple triggers
for the same object due to the same event. For example, if you have two
before insert triggers for Case, and a new Case record is inserted that fires
the two triggers, the order in which these triggers fire isn’t guaranteed.
Insert
Database.Insert
In DML statement (Insert) all the 10 records will be failed, because if one
record is incorrect or error means all other remaining records will not be
inserted. It will throw error.
We can monitor a Bulk API job in Salesforce. The monitoring page tracks
jobs and batches created by any client application.
44.Examples of some Governer limits?
6 MB/12
Total heap size
MB
You can’t add time-dependent actions to a rule if you choose Every time a
record is created or edited.
Workflow
Trigger
Audit trail function is helpful in knowing the information or track all the
recent setup changes that the administration does to the organization. It
can store last 6 months data.
Profiles help to control object privileges such as CRED (Create, Read, Edit,
Delete). They also contain system permissions that a user can carry out such
as exporting data.
A user can only have a single Profile and Role assigned to them.
Using Hard Delete your data will not be stored in the recycle bin. It will be
permanently deleted.
Using Delete user can restore those datas lated within 15days from recycle
bin
2) Logic-less Triggers
If we write methods in our Triggers, those can’t be exposed for test
purposes. We also can’t expose logic to be re-used anywhere else in your
org.
Singleton:
Strategy:
Decorator:
Implementing Bulk State transition ensure that the bulk action is performed
based on the change of bulk record state.
SOAP API:-
REST API :-
2)Preferred for mobile and web apps since JSON being Lighter the app runs
smoother and faster
You can also use Apex SOAP and REST Web services to expose data from
platform or allow an external application to invoke Apex methods.
Example: A user has salesforce and twitter account which are linked to each
other. When a user change address in twitter, his address should also get
changed in salesforce. For doing so we will use platform events to provide
notification for changing the address.
The attribute type is the one that will differentiate Application event from
Component event.
Lightning
Visualforce
62.Give a challenging scenario you faced and how you resolved it?
Scenario
When case is opened and it is not set to progress in two days then escalate
to supervisor and if it is not closed in fivve days escalate to supervisor.Case
is escalated based on closed date and cannot track progress.
Solution
Use time based workflow which will trigger email to the case owner
65.If batch is having 200 record and 1 record fails what will happen?
If any record fails all 200 record will fail but next batch will get executed
It can be created for Custom objects and for Case, Lead and Knowledge
Article Version
Example:
There are many Customer Care Executive in a call centre and many
customers call at a time and one executive can talk to one customer at one
time,so other customer’s calls are kept in queues. Each user should assigned
to at least one lead and same number of leads.
User need to handle assigned lead individually and all users in organization
should assigned with same number of leads, in this case we can define users
in organization as Queue and assign them one by one and in same number
using round robin lead assignment.
Public Group are team or group related user, used for a sharing data. They
are not the owner of the records (like queue) but can share the records (in
terms of access).
Public group can be created across any object.
68.User A has the button CLONE visible on Accounts, User B can not
see the button CLONE on Accounts. Why?
69.We have 2 users A and B under same profile and Role. How can
we restrict records of A to B and Vise versa?
In profile set View all data and modify all date permission to 'false'. This will
restric user to access data created by other users.
Lookup
Master Detail
74.There are 100 user. 90 user can read records, 10 users can
update records?
Second profile give read and edit permission and add 10 users.
Private
Public read only
Public read/write/transfer
78. There are five users under one profile and only one user see all
the data. Account is private. Why?
Create permission set with view all access to accounts and assign permission
set to specific user
Child records do not have Owner fields it takes parents records owner as
child records owner.
Look up relationship :
Look up relationship creates relations between two objects.
We can convert a look up to master detail provided if our existing data look
ups contain data for all records.
Also we should have "Allow reparenting' check box checked for that field
otherwise we will find master detail disabled when we try to change the data
type to master detail.
The variables which maintain the state the state through the execution
context and are unique to the execution context. Meaning, they can only be
accessed from within the execution context in which they are created and
are deleted when execution context completes.
A given execution context run on a single thread so static variable are equal
to local thread storage.
Reference: