You are on page 1of 15

Scenario Based Interview Questions

1)Why we cannot pass objects as arguments in future method?


==>Object data might change between the time you call the future method and the time it actually
executes.So,we pass record id.

2)IF downtime occurs and future method was running what will happen?

==>The Future method execution will be rolled back and will restart after downtime overs.

3)IF the future method was queued before a service maintenance what will happen?

==>It will remains in queue and when maintenance is over and resources are available it will get

execute.

4)If the batch is executed without the optional scope parameter and If in batch apex suppose we have
600 jobs and there are total 200 records to be proceeds in each transaction,so in total we have 3
transaction.If first transaction succeeds but second fails so in this case the records update done in first
transaction are rolled back or not?

==>It will not be rolled back.

5)When to use Database.Stateful in batch apex?

If we implements Database.Stateful we can maintained state across transactions.


Only instance variable hold values static members does not hold values.

suppose we have 600 jobs and there are total 200 records to be proceeds in each
transaction,so if we want to count records as batch proceeds maintaining state is important
as after 200 set of records new transaction will start and members will loose their values. By
implementing
Database.Stateful we can maintain state after transaction is over and can store previous
values.

Syntax:

global class myClass implements Database.Batchable<sObject>, Database.Stateful{

6)What are the parameters in system.schedule(Parameters) represents?

system.schedule('jobName ', expression, instance of schedulable class);

JobName represents the name for the job,


expression represents time and date at which batch should run,
"instance of schedulable class" represents instance of class which need to be schedule.

7)With the before Insert event which context variable is correct Trigger.new or
Trigger.newmap?

As the event is before insert only trigger.new will be supported.

Trigger.newmap will not be supported as we do not have id of record before the record is
inserted.

8)What will you do if a method inside apex class need to be executed only when it is getting
called from trigger?

We will use trigger.isexecuting in apex class to check if the method inside apex class is
getting called from trigger and will execute the method if getting called from trigger.

9)What will happen if you forgot to store remote site url in remote site setting?

The callout to external system will fail.

10) How to query object having more than 50,000 records?

The total number of records that can be queried by soql queries is 50,000 record. If we query more
than 50,000 record we exceeds the heap limit.

To avoid this we should use SOQL query for loop it can process multiple batches of record using call to
query and query more.

for (List<Account> acct : [SELECT id, name FROM account

WHERE name LIKE 'Test']) {


// Your logic here

//A runtime exception is thrown if the below query returns enough records to exceed your
heap limit.

Account[] accts = [SELECT id FROM account];

11) Is it possible to call a batch class from trigger and is it possible to make a
call to apex callout method from trigger?

Yes it is possible to call a batch class from trigger but in case of call to apex
callout method the method needs to be asynchronous.
12) Why we should avoid using SeeAllData=true in test class?

It might happen that the test class pass in sandbox but fails in production if we do not have
the same record in production.

13) If we are using @testSetup in test class and let say we have two test methods
in the same test class which are using the data from @testSetup and
performing operations on data, so in this let say if i am updating data from
@testSetup in first test method and also using the data from @testSetup in
second test method whether i will get the fresh data or the updated data in
second test method.

operation done on the records from @testSetup are local to the test method only, so i will
get fresh data in second test method as well.

Sample example:

@isTest
Public class testclass
{
@testSetup
static void testsettingup()
{
contact obj=new contact();
obj.firstname='test';
obj.lastname='data';
insert obj;

}
static testmethod void testmethodname() //No parameter inside test method
{
test.starttest();
contact obj1=new contact();
obj1=[Select id,firstname from contact where firstname='test'];

obj1.firstname='test1';
update obj1;
// operation done on the records from @testSetup are local to this test method only.

test.stoptest();
}
}

14) How many times a test method can call test.starttest() and test.stoptest()?

Each test method can call start test and stop test only once, but number depends on the
number of test methods in test class.
15) What will happen if a class is not declared with "With sharing" or "Without
sharing" and it get called from another class which is declared with "With
sharing"?

If we do not declare class with "With sharing" or "Without sharing" the class will not take
into account the sharing rules but if this class is called from another class which is declared
with "With sharing" it will take into account the sharing rules.

16) IF the class with "With sharing" is calling method of another class with
"Without sharing" what will happen?

IF the class with "With sharing" is calling method of another class with "Without sharing"
than the method inside "Without sharing" class will execute without sharing rules.

17) IF the class with "Without sharing" is calling method of another class with
"With sharing"
what will happen?

IF the class with "Without sharing" is calling method of another class with "With sharing"
than the method inside "With sharing" class will execute with sharing rules.

18)Let say user do not have permission on a child object and he is having
permission on parent object to read/create/edit/delete parent object,If I create
a trigger on parent object to insert a child record after parent record is
created,will it create a child record or not after user insert parent record
manually?

It will create a child record. (Trigger/apex class runs in system mode)

19)If in (question 18) from trigger I am calling apex class which is in "with
sharing" mode and where i am inserting child record after parent is inserted
manually by user so will it create a child record?

It will create a child record.(With sharing keyword has nothing to do with user
permissions).

20) What will happen if we forgot to enable mydomain?

We must deploy My Domain in our org if you want to use Lightning


components otherwise we would not be able to see the output of lightning
components.

21) What are the different type of pages we can create using lightning component and what are the
different types of component supported in lightning pages?

We can create different types of pages using lightning app builder,

1)App Page
2)Home Page
3)Record Page

Components type supported in Lightning pages:

1) Standard Components:

Standard components are Lightning components that are built by Salesforce.

2) Custom Components:

Custom components are Lightning components we creates.


3) Third-Party Components on AppExchange

On AppExchange we can find packages containing components that are ready to use in lightning app
builder.

22) What are required parameter while declaring attribute in lightning component?

Name and type are parameter of attribute which are always required in attributes,description is
another parameter where we can mentioned about description of attribute.Description is not an
required attribute. Similarly we have default parameter to give some default value to attribute.To set
the access for an attribute we have access parameter where we can specify about
public,private,global access for an attribute.By default the attribute have public access.

23) Which type of attribute we can use in lightning component to store fractional values?

Doubletype.

24) When to use Decimal type attribute in lightning component?

Decimal is better than Double for maintaining precision for floating-point calculations.
It’s preferable for currency fields.

25) Let say we are storing some default values in map attribute.

<aura:attribute type="Map" name="Mapattribute" default="{1:'value1',2:'value2'}" />

How to retrieve value from this attribute?

Retrieve values by using cmp.get("v.Mapattribute")['1'].

26) To form a container around a information related to single item or group of item what we need
to use in lightning component?

Lightning:card.
27) How to obtain the id of the current record in lightning component?

By using force:hasRecordId interface in lightning component we can assigned the id of the current
record to lightning component. This interface adds an attribute named "recordId" to the component.
The type of attribute is string and has 18-character Salesforce record ID.

28) you are asked to override the standard action using lightning component how you will achieve
this?

Lightning:actionOverride interface Enables a component to be used as an override for a standard


action. We can override the View,New, Edit, and Tab standard actions on most standard and all
custom components. The component needs to implement the interface Lightning:actionOverrideafter
which the component appear in the Lightning Component Bundle menu of an object action Override
Properties panel.

29) Which interface you will implement in lightning component if you want your component to be
available only for record detail page?

Interface flexipage:availableForRecordHome make the component available for record pages only.

30) you are asked to create a component for some requirement and create a tab for the same in
lightning experience what you will do to achieve this?

Interface force:appHostable in component allow it to be used as a custom tab in Lightning


Experience or the Salesforce mobile app.

31) On load of lightning component you are required to execute some action what you will do to
achieve this?

We will use "Init" Event which is also called as the constructor of lightning component.The init event
is called once the component construction is over.

Basic Syntax:
<aura:handler name="init" value="{!this}" action="{!c.doinit}"/>

32) you are asked to execute some action when value change is detected in one of the attribute what
will you do?

We will use "change" Event.

The change event is called when the value in one of the attribute changes.
As an Example If i am having attribute " Anyname", on change of attribute "Anyname" if i want to
call javascript method i can do this as:

Syntax:

<aura:attribute name="Anyname" type="String" />


<aura:handler name="change" value="{!v.Anyname}" action="{!c.doinit}"/>

33) You are having a requirement to pass value from child component to parent component which
type of event you will use?

We will use Component event. Component event are used in case when there is a relationship
between component. Component Events are fired by the child components and handled by the parent
component.

34) You are having a requirement to pass value from one component to other component which are
not related but a part of same application which type of event you will use?

We will make use of Application event. Application event are the event handle by any component no
matter what relationship between them but they should
be inside single application.

35) Explain the event propagation rule for application event and component event?

Event Propagation Rules


36) You are calling child component from Parent component and passing one of the attribute value
from Parent component to child component attribute while calling child. What will you do if you want
to binding both parent and child component attribute?

I will make use of bound expression,

AttributeNameFromChild="{!v.AttributeNameFromParent}" is a bound expression. Any change to the


value of the childAttributeName attribute in child component also changes the value of
parentAttributeName attribute in parent component and vice versa.

<aura:component>
<c:ChildComp childAttributeName="{!v.parentAttributeName}" />
</aura:component>

37) You are calling child component from Parent component and passing one of the attribute value
from Parent component to child component
attribute while calling child. What will you do if you do not want to bind parent and child component
attribute?

I will make use of unbound expression,

AttributeNameFromChild="{#v.AttributeNameFromParent}" is a Unbound expression. Any change to


the value of the childAttributeName attribute in child component has no effect on the value of
parentAttributeName attribute in parent component and vice versa.

<aura:component>
<c:ChildComp childAttributeName="{#v.parentAttributeName}" />
</aura:component>

38) You are in a need of passing a value from Parent component controller to Child component
controller what will you do?

We will make use of Aura:method.

39) How to ensure field level security while working with lightning components?

Make use of Lightning:recordForm or Standard controller of lightning component (force:recordData).

40) How to use lightning component with visualforce page?


Make use of lightning Out feature.

41) Lightning component is what type of framework?

It is a component based framework. It is an event driven architecture. It can called as a MVCC


framework which has two controller, one is client side and other is server side.

42) How to use lightning component with Salesforce mobile app?

Make a tab for lightning component and include this tab in Salesforce1 mobile navigation.

43) What are the requirement to call a server side controller method from Javascript controller?

Method should be static and must be Aura enabled using @AuraEnabled.

44) We have a requirement to create account using new button and default some values in
the new account screen how we can achieve this requirement?

We can make use of force:createRecord, force:createRecord is an event that opens a page to


create a record for specific entity.

Sample syntax:

createRecord : function (component, event, helper) {


var createRecordEvent = $A.get("e.force:createRecord");
createRecordEvent.setParams({
"entityApiName": "ObjectApiName"
});
createRecordEvent.fire();
}

defaultFieldValues attribute inside setParams let us auto populate value on fields inside
record form.

Sample Example to create account:

COMPONENT:

<aura:component implements="flexipage:availableForAllPageTypes">
<lightning:button label="New Account" onclick="{!c.createAccount}"/>
</aura:component>

CONTROLLER:

({
createAccount : function(component, event, helper) {
var recordEvent=$A.get("e.force:createRecord");
recordEvent.setParams({
"entityApiName": "Account",
"defaultFieldValues":{
"Industry":"Apparel"
}
});
recordEvent.fire();
}
})

45) When CRUD operations can be performed by form-based components like


lightning:recordForm, lightning:recordViewForm, lightning:recordEditForm
taking field level security into consideration so what is the need of force:recordData?

force:recordData is known as standard controller of lightning component


similar to we have standard controller in visualforce page. On its own, force:recordData
does not have inbuilt UI. We need to define the fields for taking inputs. The lack of UI
elements makes it a powerful addition. We can use it to create highly customizable user
interfaces beyond what the form-based components provide. We can use custom
components to display the data fetched by force:recordData.

46) What is target attribute and fields in force:recordData represents?

Sample syntax:

<force:recordData aura:id="someId"

recordId="{!v.recordId}"
layoutType="{!v.layout}"
fields="{!v.fieldsToQuery}"
mode="VIEW"
targetRecord="{!v.record}"
targetFields="{!v.simpleRecord}"
targetError="{!v.error}"
/>

target attributes are attributes that force:recordData populates itself.


1) targetRecord is populated with the loaded record
2) targetFields is populated with the simplified view of the loaded record
3) targetError is populated with any errors

fields specifies which fields in the record to query.

47) What is the use of recordUpdated event in force:recordData?

For every force:recordData component referencing the updated record, LDS


does two things.

 LDS notifies all other instances of force:recordData of the change by firing the
recordUpdated event with the appropriate changeType and changedFields value.
 It sets the targetRecord and targetFields attribute on each force:recordData to the
new record value. If targetRecord or targetFields is referenced by any UI, this
automatically triggers a rerender so that the UI displays the latest data.

Note: If force:recordData is in EDIT mode, targetRecord and targetFields are not


automatically updated.

You might also like