Salesforce Scenario Based Interview Questions and Answers | Part 3
Summary
TLDRThis video explores advanced Salesforce interview questions, focusing on Apex, asynchronous Apex, and Lightning Web Components (LWC). It delves into Salesforce's request pipeline, discussing the execution order of automation tools and the impact of validation and workflow rules. The presenter also addresses the use of platform events for handling asynchronous operations in LWC, the application of user permissions in Apex, and the intricacies of DML operations across multiple objects. Additionally, the video covers the differences between 'with sharing' and programmatic sharing in Apex, the behavior of queueable jobs, and lead conversion ownership. The script aims to prepare viewers for technical Salesforce interviews by covering these complex topics.
Takeaways
- đ Salesforce interviews often ask scenario-based questions involving Apex, asynchronous Apex, admin, Integrations in LWC, and other Salesforce tools.
- đ„ The speaker has created a series of videos covering LWC from basic to advanced topics, with links provided in the description for further learning.
- đ The order of execution for Salesforce automation tools is governed by the 'wave of execution', where validation rules execute before workflow rules.
- đ« A validation rule conflict scenario reveals that a record might not be saved due to validation rule conditions, highlighting the importance of rule design.
- đ Custom validation rules do not rerun if a field update is made by a workflow rule, which is considered a loophole in the Salesforce execution pipeline.
- đĄ Future methods in Apex, being asynchronous, cannot directly show callout responses in LWC components, but can be achieved using platform events and the Lightning Message Service.
- đ Understanding Salesforce security and sharing models is crucial, as demonstrated by the scenario involving object permissions and DML operations in triggers.
- đ Apex code typically runs in 'system mode', bypassing user permissions, but Salesforce provides ways to enforce 'user mode' for respecting permissions during DML operations.
- đ The difference between 'with sharing' and Apex 'manage sharing' settings is explained, with the former enforcing sharing rules and the latter allowing programmatic sharing of records.
- â If a transaction rolls back after submitting a queueable job, the job will not be processed, emphasizing the relationship between transactions and asynchronous jobs.
- đ Lead conversion in Salesforce changes the ownership of the Opportunity, Account, and Contact records to the user who performs the conversion, not the original lead owner.
Q & A
What is the order of execution for automation tools in Salesforce?
-In Salesforce, the order of execution is predefined and known as the governor execution order. Validation rules execute prior to workflow rules, and custom validation rules do not run again if field updates are made by workflow rules.
Why are custom validation rules not re-executed after a workflow rule modifies a field?
-Custom validation rules are not re-executed after a workflow rule modifies a field because Salesforce's governor execution order dictates that only triggers and standard validation rules run again if a field update is made by a workflow rule.
Can we show the response of a future method callout on a Lightning Web Component (LWC)?
-Directly showing the response of a future method callout on an LWC is not possible because future methods are asynchronous and execute in a separate thread. However, using platform events to publish and subscribe to the callout response can achieve this.
How can we handle permissions when inserting a record from a trigger in Salesforce?
-Salesforce triggers run in system mode by default, which means they bypass user permissions. To enforce user permissions, you can use Apex code with user mode settings, such as `Database.enforceUserMode` or by using schema methods or user mode database operations.
What is the difference between 'with sharing' and Apex 'manage sharing' settings?
-'With sharing' is a keyword used in Apex classes to enforce sharing rules for specific classes, ensuring that queries respect the user's permissions. 'Manage sharing' in Apex allows for programmatic sharing of records, where you can insert sharing records to grant access to specific users.
What happens to a queued job if the submitting transaction is rolled back?
-If the submitting transaction is rolled back, the queued job will not be processed, as Salesforce does not execute asynchronous jobs in such cases.
Who becomes the owner of the opportunity, account, and contact after a lead conversion?
-After a lead conversion, the user who is converting the lead becomes the owner of the opportunity, account, and contact, regardless of the original lead owner.
Can we perform DML on multiple objects in a single DML operation in Salesforce?
-Yes, you can perform DML on multiple objects in a single DML operation by using a generic sObject list and adding different object records to it. This is possible as long as there is no parent-child relationship between the objects.
How can we save related objects in a single transaction in Salesforce?
-You can save related objects in a single transaction by using an external ID as a foreign key to create parent and child records in a single DML operation.
Can we set the calling order of wire methods in LWC?
-Directly setting the calling order of wire methods in LWC is not possible, as they are called automatically by the framework. However, dependencies can be managed by passing reactive parameters to dependent wire methods, causing them to re-call when the parameter value changes.
Outlines
đ€ Salesforce Interview Q&A on Apex and Validation Rules
This paragraph discusses scenario-based interview questions for Salesforce roles, focusing on Apex, asynchronous Apex, and validation rules. The video script explains how Salesforce handles conflicting validation rules during record insertion and saving, emphasizing the order of execution for Salesforce automation tools. It clarifies that validation rules are executed before workflow rules, and how this can lead to unexpected outcomes, such as a record being saved with a blank 'website' field despite a validation rule requiring it to be non-blank. The paragraph also touches on the importance of understanding the order of execution in Salesforce's automation pipeline.
đ Salesforce Security and DML Operations in Triggers
The second paragraph delves into Salesforce security models and DML operations within triggers. It examines a scenario where a user with permissions on Object A but not on Object B attempts to insert a record into Object B from a trigger on Object A. The explanation covers system and user modes in Apex execution, highlighting that triggers run in system mode by default, thus bypassing user permissions. The paragraph also explores Apex's ability to enforce user mode with specific code approaches, such as using schema methods or user mode database operations, and discusses the implications for record ownership and accessibility post-insertion.
đ Performing DML on Multiple Objects and Understanding Sharing Settings
This paragraph explores the capability to perform DML operations on multiple objects within a single statement in Salesforce, demonstrating how to insert records of different objects into a single DML statement. It also discusses the possibility of saving related objects in a single transaction using an external ID as a foreign key. The paragraph further explains the difference between 'with sharing' and Apex managed sharing settings, detailing how 'with sharing' enforces sharing rules within an Apex class, while managed sharing settings allow for programmatic sharing of records in Apex.
đ Impact of Transaction Rollbacks on Queueable Jobs and Lead Conversion Ownership
The final paragraph addresses what happens to queueable jobs if the submitting transaction is rolled back in Salesforce, clarifying that such jobs will not be processed. It also discusses the ownership dynamics during the lead conversion process, explaining that the owner of the lead becomes the owner of the newly created opportunity, account, and contact records. Additionally, the paragraph touches on the topic of setting the calling order of wire methods in LWC components, suggesting the use of reactive parameters to manage dependencies between wire methods.
Mindmap
Keywords
đĄSalesforce
đĄValidation Rule
đĄAsynchronous Apex
đĄLightning Web Components (LWC)
đĄPlatform Events
đĄObject-Specific Security
đĄSystem Mode vs. User Mode
đĄDML Operation
đĄWith Sharing
đĄApex Managed Sharing
đĄQueueable Job
đĄLead Conversion
đĄWire Method
Highlights
Introduction to scenario-based interview questions for Salesforce roles.
Explanation of Salesforce request pipeline and the execution order of automation tools.
How validation rules and workflow rules interact in Salesforce, leading to a potential loophole.
Using platform events to communicate between future methods and LWC components.
The impact of Object-Specific Access settings on DML operations within triggers.
Difference between system and user modes in Apex and their effect on permissions.
How to perform DML on multiple objects within a single operation in Salesforce.
Using external IDs to save related objects in a single transaction.
Clarification on the difference between 'with sharing' and programmatic sharing in Apex.
Behavior of queueable jobs when the submitting transaction is rolled back.
Lead conversion process and how ownership is determined for opportunity, account, and contact.
Managing the calling order of wire methods in LWC components using reactive parameters.
The importance of understanding wardrobe execution in Salesforce for effective automation.
How to enforce user mode in Apex to respect user permissions during DML operations.
The role of platform events in asynchronously handling responses from future methods.
Strategies for handling complex sharing conditions that cannot be met with standard sharing rules.
The practical application of external IDs in DML for creating related records in a single transaction.
How to control the flow of data between wire methods in LWC using reactive properties.
Transcripts
foreign
[Music]
series
in which I have already created two
videos and covered many scenario based
interview questions and if you want to
learn about them then please check out
those videos and you can find Link in
description
all right so today in this video we will
see more scenario based interview
questions
which are generally asked in most of
Salesforce interviews
and we will cover questions related to
apex asynchronous apex admin
Integrations in lwc
and I already have created lwc specific
in two questions and answers series
in which you will find multiple videos
which covers from basic to Advanced lwc
interview questions
so if you want to learn only lws related
questions and answers then you can refer
those videos and you can find Link in
description okay
so let's start with today's first
question
so the question is
suppose we have a validation rule on
account object to make website field
required and on same account object we
have a validation rule to make website
feel blank
now we have two scenarios here
first we have what will happen if we try
to insert record without website and
another we have what will happen if we
save it with website okay so this
question is related to or drop execution
and you know we have lots of tools and
ways to inject our custom Logics and
functionalities in Salesforce request
pipeline
like triggers flows workflows process
Builders approvals and many other tools
are available in Salesforce
so using these tools we can inject our
custom Logics in between Salesforce
application pipeline for example you
want to create tasks when opportunity
get created then you can use flows or
trigger to create task decode when
opportunity record get created okay so
now the question is in which order all
these tools will get executed
like who will get execute first and who
will get execute next right so
Salesforce already has a predefined
order to execute all these automation
tools that is called wardrobe execution
and as per this wardrobe execution
validation rules execute prior to
workflow rules
so in our first scenario where we are
not providing website then validation
rule condition will become true
and request will be written from here
only so in first case record will not
get saved into database and error
message will appear okay now if we talk
about second scenario
where we are giving website
then validation rule condition will
become false so request will move
further and reach to workflow rule now
what this workflow rule will do
it will make that website field blank
okay now what will happen without
validation rule because you know we have
a validation rule to make sure website
field should not be blank
but after executing validation rule
workflow rule making it blank so as per
outro Constitution if we are making any
field update from workflow rule then
only triggers and standard validation
rules run again not custom will listen
rules so our record will get saved
without website I mean website field
will be blank
why this is happening
because custom validation rules are
already executed and after that workflow
rulemaking website will be blank and as
Pro drop execution custom validation
rules will not run again so we can say
this is a loophole in Salesforce
pipeline
so in nut sale custom validation rules
will not run if you are making field
update from workflow rules okay
and wardrobe execution is very important
topic in Salesforce so if you want a
separate detailed video on this then do
let me know in the comments
now next question we have
can we show future method called out
response on UI in lwc component
it means we have a future method
and Performing call out from that
then is this possible to show call out
response on lwc component
then directly this is not possible
because the written type of future
method is void and you know future
method is the part of asynchronous Apex
and asynchronous Apex will get executed
in another thread so we don't have any
control in that and won't be able to
return anything from there
but we can use platform events to get it
done
like from future method we can publish a
platform event and in lwc component we
can subscribe that platform event with
the help of EMP APA module
so you can see here in this example I
have a future method and making call out
from here
and At Last I am publishing platform
again from here
and here in this lwc component
in Connected callback I have subscribed
that platform even with the help of EMP
IPA module
and this respond Handler better will get
executed whenever any platform event
will get published
so you can put your Logics here
and we are passing this response Handler
over here with the subscription okay so
in nut sale directly we can't achieve
this
but with the help of platform events we
can show future method call out response
in lwc component okay
now next we have let's say we have two
objects
object a and object B and rwd is set to
private for both objects
now suppose user has permission on
object a
but don't have any permission on object
B now if you are going to insert object
B record from object a trigger
then what will happen in this case Okay
so this question just want to check your
Salesforce security or sharing model
knowledge
and let's understand this question again
so as per this question we have two
objects object a and object B and o w d
or by default is set to private for both
objects and current user has full
permission on object a but don't have
any permission on object B and you know
user has a permission on object a so
whenever he will try to save the code
then trigger will get called and try to
insert recording object B and as we have
seen user don't have any kind of
permission on object B
so now the question is what will happen
here will this object be record insert
or not okay so I think now you are clear
that this is the case of permissions
so in Salesforce generally we have two
modes which can be applied on apex while
execution
first is system mode and another one is
user mode
so system mode means run Apex code By
ignoring user permissions like who is
the logged in user and what all
permissions he has that doesn't matter
and if you are running Apex code in
system mode then user permissions are
bypassed there
and it can access all objects fields and
Records By ignoring profile permission
set and sharing rules okay
and user mode means running Apex code
will respect user permissions and can
perform only permitted operations for
example if user don't have permission to
save record and if still you are trying
to save then it will throw error so in
nut sale system mode bypass user
permissions
and user mode will follow user
permissions okay
and system mode is the default mode for
Apex code I mean wherever we write Apex
code like Apex classes triggers and
asynchronous Apex then that will execute
in system mode
so when we are saving records from
trigger then it will be saved without
checking user permissions okay
but Salesforce provided few ways to
enforce user mode with FX code
so there are multiple approaches which
you can use to enforce user mode and
whenever you are going to answer this
question then please don't say about
with sharing keyword because first of
all we can't use with sharing keyword
with triggers and with setting only
check into code level permissions not
object and fill level
for objects and field level permissions
you can use schema methods or nowadays
Salesforce introduced user mode database
operations as well
like instead of doing all DML operations
like this we should write DML operations
in this form if you want to enforce user
mode
like here we need to add add user
or if you are using database methods
then you can pass access level as a
parameter okay
and there are many other ways to apply
user permissions with Apex code like
with security enforced and security dot
stripe inaccessible those I will discuss
in separate video because this is a long
topic so in nut cell our triggers run in
system mode
and if we are additionally not enforcing
user mode
then it will insert record without
permissions as well so in this case
record for object B will be inserted
from trigger
okay
now introvert can also ask you like
let's say we are not using additional
approach to enforce user mode then
record will be inserted right
now how user can access that record
so if you are talking about the owner
like who will be owner of that record
then technically the user who initiated
the request will be the owner
and we have private owd then it should
show in the list of user
but you know we don't have permission on
object level
so there is no way on UI to see that
record so in nut sale user won't be able
to access that record okay
now next we have can we perform DML on
multiple objects in single DML operation
so let's understand this question a
little bit more
so let's say we have to insert data in
five objects
and you want to save your DML Governor
limits and you know in one DML operation
we can insert up to 10 000 records
so the question is can I insert these
five object records using single DML
operation
instead of five separate DML operations
okay so now I think you got the question
so let's discuss on answer so the answer
is yes we can insert multiple objects
records in single DML statement as well
and you can see in this example
we have to declare a generic s object
list
and in this generic s object list
we can add our different different
object records like here I am adding
object a object B C D and E
so I am adding five objects records here
in this generic cache object list
and at last we can perform DML operation
like this
okay
so this will perfectly work
and you know all these objects are
independent
and there is no parent child
relationship between these objects
now the question is can we save related
objects in single transaction
because there we require parent record
ID in child record right
so the answer is yes
we can use external ID as a 4M key to
create parent and child record in single
DML so this is the example you can see
here
I'm inserting a portrait in account in
single DML
so what I did here first I have created
object or the opportunity
then I have created object for account
but only provided external ID
and edit this account object in this
opportunity load account field
now here I have created a separate
object for account record
and here also I'm providing same
external ID
okay
and At Last I am performing DML
operation and providing both objects
here like account and opportunity so
with the help of this external ID
Salesforce internally map these records
okay
so in that sale we can perform DML on
multiple objects in single DML operation
okay
now next we have what is the difference
between with sharing and Apex manage
setting
okay so first let's discuss about with
sharing
so which setting is the keyword that we
generally use with Apex classes to
enforce sharing rules
for example let's say we are querying
data from FX class using soql and by
default Apex runs into system context
and if we Define owd private for an
object then in system context
SQL will return all the data without
carrying up sharing rules
and if we are using with sharing keyword
with class definition
like this
then it will enforce sharing rule for
particular class and all the queries
written in that class will follow
sharing rules and return only allowed
records for the user okay
and now if we talk about Apex manage
setting then we can say this is the type
of programmatic sharing which allows you
to share a record from Apex
so generally we Define Baseline record
sharing with owd org white default
like in owd we can Define who can access
and modify which records so generally we
have three options for object public
read write
it means anyone can see and edit all the
records
and public read only means anyone can
see all the records but only can edit
their own records
and private means
user can only access or modify their own
records okay
so these settings we can do at object
level in owd
but let's say you want to share user
records with their managers anyone who
is in higher role hierarchy
then you can use role hierarchy checkbox
option
and now let's say
we have private owwt on an object and if
you want to say records with other users
then we can use sharing rules and we can
create sharing rules in two ways owner
based or criteria based so whenever you
want to share a particular user records
with role or group then you can use
owner-based sharing and if you want to
say records using with some conditions
then you can use criteria based sharing
for example you want to share all closed
lost opportunities with another group
then you can use criteria based sharing
okay
but let's say you have a complex
condition that cannot be implemented in
Sharing rules now if you want to say
records then you can use FX sharing and
this is the example of Apex mini setting
so in Salesforce each object has their
additional sharing object
we don't have to additionally create it
it is built in feature in Salesforce and
the sale object contains all the record
sharing details
but if you want to share any object from
Apex
then you have to insert new record into
this and you need to provide here which
record you want to share with which user
okay
so you can see here I have job custom
object
now here I am telling this record I want
to share and here I am giving the user
ID
to whom I want to share this record
and here we can Define the access level
and at last we can insert this recording
to Salesforce database
so this is how we can say array record
with the help of Apex
so in nut sale with sharing and for
sharing rule in Apex classes
and minutes setting is used to
programmatically save records okay
now next we have what will happen if f x
transaction roll back after nkqable job
so it means let's say you are submitting
a queueable job from Apex transaction
but somehow if current transition get
rolled back then what will happen with
that queueable job
will that still execute or not because
you know curable job is the part of
asynchronous Apex and asynchronous Apex
get executing different thread but if
submitting transaction get rolled back
then Salesforce does not execute
asynchronous jobs as well okay
so answer will be no job will not
processed okay
now next we have assume we have a lead
and owner of that lead is q
then after conversion who will be the
owner of opportunity account and contact
so this question is related to sales
lead conversion process
so you know a lead can be owned by
multiple users with the help of queue I
mean we can set a queue as a lead owner
so multiple users can work on the same
lead
but when we convert lead into
opportunity
then generally Salesforce created three
objects opportunity account and contact
and by default lead owner is the owner
of these three objects but we can't set
queue as a owner of these objects
then who will be the owner of these
records
okay so the owner will get changed
automatically to the user who is
converting the lead
so we can say current user who is
converting the lead will be the owner
okay
now next we have can we set calling
order of wire methods in lwc or in other
words can we call one wire method after
another in lwc so you know we can have
multiple wire methods in same lwc
component and one wire method may be
dependent on another I mean you may
require one wire methyl response into
another so how we can handle this
situation because you know wire methods
call automatically wipe framework we
don't have any control on that
so directly this is not possible but
what we can do we can pass reactive
parameters in dependent wire method and
change that parameter value from first
wire method
and reactive parameter means whenever
the value of parameter will get changed
then wire method will call again so
let's understand this with example so I
have two wire methods here to get
accounts and contacts
in first method I am getting accounts
list
and in second I am getting account
contacts list and passing account IDs
parameter and here I'm assigning account
ID property with dollar sign so this is
how we can make a parameter reactive
we just need to add dollar with property
name okay
now in first method when I get accounts
then I'm assigning first account ID to
this account ID property
and when this account ID property value
will get changed then this get context
method will again call due to this
reactive parameter okay
so directly there is no way to control
calling order of wire methods but we can
say dependencies using reactive
parameters so whenever parameter value
will get changed then wire method will
recall okay
so that's it for this video and if you
want more videos in this series then do
let me know in the comments and if you
learned anything new from this video
then please like And subscribe my
YouTube channel
I will see you in next video
Voir Plus de Vidéos Connexes
Salesforce Apex Interview Questions & Answers #salesforce #apex #interview
Display Images in Oracle APEX Interactive Reports and Forms - Part 8
C# Async/Await/Task Explained (Deep Dive)
Exploring Interactive Grid in Oracle APEX - Part 6
Javascript Promises vs Async Await EXPLAINED (in 5 minutes)
Redux - Complete Tutorial (with Redux Toolkit)
5.0 / 5 (0 votes)