Professional Documents
Culture Documents
Apex Interview Questions
Apex Interview Questions
Apex Interview Questions
Apex is easy to use as it uses the syntax like Java. For example, variable declaration, loop syntax
and conditional statements
6) What is $A.enqueueAction(action)?
ANSWER:-
$A.enqueueAction(action) sends the request the server. More precisely, it adds
the call to the queue of asynchronous server calls. That queue is an optimization
feature of Lightning
7) write down the syntax of list set and map and tell me about
the diffrance between them
ANSWER:-
List<String> lists = new<List> ();
Set<String> sets= new<String> ();
Map<id, value> maps= new map<id, value>();
List Set Map
The list interface Set does not allow The map does not allow
allows duplicate duplicate elements. duplicate elements
elements
The list maintains Set do not maintain The map also does not
insertion order. any insertion order. maintain any insertion order.
We can add any But in set almost The map allows a single null
number of null only one null value. key at most and any number
values. of null values.
8) Whatever the query language in the salesforce like how many query
language in the salesforce
Answer:- Like there are two language we can use to salesforce
Which is 1)SOQL 2)SOSL
10) What are the best practice while writting the trigger
ANSWER:-
1) one object on trigger
2) Bulkification
3) Use soql query for loop
4) Use only required event
5) Use context specific handler method
11) Use unique Naming convention
11 )What are the best practice while writting in test
classAnswer:-
1) test class have must writtern @isTest
2) 75% code coverage is required
3) One assert statement is required per method 1 assertEquals
4) You can use @isTest or testmethods
5) Create test Factory class using @isTest Method
6) Avoid using hard code
38)How many events do we have in Aura components? How are they used?
Answer: There are three types of events:
39)What is Database.Stateful..?
Ans:- If we have to have the total count the records which were processed in the batch apex, should we use
both Database.stateful
ANS:-Master-Detail Relationship:
It is a tightly coupled record that has a direct dependency between the two objects. It can also
be described as a parent-child relationship.
The record of detail cannot be created without a master.
The sharing rules are inherited from the master to the detail record.
We cannot update the relationship to the master in a master-detail relationship.
The number of master-detail relationships that can be used is limited to 2.
Master-detail relationships are automatically included in report record types.
We also cannot set the profile object permissions for the record of detail.
If a master record is deleted then the record of its detail also gets deleted along with it, that is, it
implements cascade delete.
Roll-Up Summary can be created on a master detail.
Lookup Relationship:
This type of relationship can be used when we just need to have the relationship between two
objects but not a direct dependency on each other.
This is a loosely coupled relationship.
These are used to reference commonly shared data, such as reference data.
The maximum number of lookup relationships in a field can be 40.
They are used to link two objects together when we do not want to have the behavior of the
master-detail like sharing rules, profile permissions, and cascade delete.
Lookups are used when we need to relate multiple ‘parents’ to the record of detail.
Deletion of the parent just deletes the related field in the child but not the whole record.
This type of relationship is also like a one-to-many relationship.
46)what is profile?
ANS:-A profile is a group/collection of settings and permissions that define what a user can
do in salesforce. A profile controls “Object permissions, Field permissions, User permissions, Tab
settings, App settings, Apex class access
@InvocableMethod annotation is required for calling any apex method from flow.
For Flow, care should be taken to retrieve records once and then loop through them rather than
repeatedly retrieving records through multiple loops (this is equivalent to not performing SOQL
within a loop).
48)Can we change the data type of variable once we have created in lightning flow designer?
The advantage is that earlier, we had to create custom fields to group or segment certain data.
Dynamic dashboards are used to display information which is tailored to a specific user. Let us
consider the same example as above. In case the Sales manager wants to view the report
generated specific to only one of his team members, then he can use dynamic dashboards.
You can use dynamic dashboards when you want to show user-specific data of a particular user,
such as their personal quotas and sales, or number of case closures, or leads converted etc.
You can also use a normal/ static dashboard when you want to show regional or organization-wide
data to a set of users, such as a particular region’s sales number, or a particular support team’s
performance on case closures.
As far as the second part of the question is concerned, no we cannot schedule a dynamic
dashboard. That is because whenever we open the dashboard, it will show the data generated in
real-time
58)Cross object..?
ANS:-A Cross-object formula is a formula that spans two related objects and references merge
fields on those objects. A cross-object formula can reference merge fields from a master
(“parent”) object if an object is on the detail side of a master-detail relationship. A cross-object
formula also works with lookup relationships
ANS:-Process Builder and Workflows both tools are used to automate business processes.
Process Builder is more advanced than workflows. It extends upon the things that workflow does.
The major difference between workflows and process builder is the number of operations or actions they have.
Workflows enable us to set up rules that are evaluated and the corresponding action is executed based on the type of change
in record.
Actions of workflows:-
Create Task
Update Field
Email Alert
Outbound Message
Process Builder brings a visual designer with it. Whereas the visual designer is not available in Workflows.
For updating related records, Process Builder can update any field on any related record.
Whereas Workflows can only update some fields on a parent record of a Master-Detail relationship.
68)What is Campaign..?
ANS:-A Salesforce Campaign is a group of Leads and Contacts exposed to specific marketing
communication(s). It stores essential performance metrics and means salespeople can quickly see the
customers and prospects that received marketing activity
69)write down the syntax of list set and map and tell me about
the diffrance between them
Ans:- A list is an ordered collection of elements that are distinguished by their indices. List elements
can be of any data type—primitive types, collections, sObjects, user-defined types, and built-in Apex
types.
A map is a collection of key-value pairs where each unique key maps to a single value. Keys and values
can be any data type—primitive types, collections, sObjects, user-defined types, and built-in Apex types.
A set is an unordered collection of elements that do not contain any duplicates. Set elements can be of
any data type—primitive types, collections, sObjects, user-defined types, and built-in Apex types.
70)Whatever the query language in the salesforce like how many query
language in the salesforce
Ans:- There are two query language in salesforce
1) Soql
2) sosl
73) What are the best practice while writting in test class
Ans:- 1)test class must have written @isTest
2)75% code coverage is required in the test class
3) one assert statement requird for one method
4) Avoid using hard code
80)Can we call batch apex in batch apex if yes then how to call it..?
Ans:- There are two ways in salesforce which are used to call the batch class from another batch class
are: Using Queueable Apex. Using the Finish method of Batch class
83)What is Aura:Method..?
Ans:- Use to define amethod as part of a component's API. This enables you to
directly call a method in a component’s client-side controller instead of firing and
handling a component event. Using simplifies the code needed for a parent
component to call a method on a child component that it contains.
1.1 Profiles
In Salesforce, profiles control access to object-level and field-level security among other things like
apps, tabs, and so on.
Since Maria is a new employee, an admin needs to add John to the appropriate profile that has
access to sales apps and related objects to begin giving her access to Salesforce data.
Since John has a marketing background, let’s say she wants to access the Campaigns object to help
with marketing. The admin wants to give permission to access Campaigns just to John. This is where
permission sets come in. Permission sets are used to provide additional (usually special)
permissions to users who are already in a profile. In our case,an admin needs to create a permission
set that provides access to the Campaigns object and assign that permission set to Maria.
.
1.
With permission sets, you can add and remove permissions to a small
subset of users at any time.
You can add multiple permission sets to a given user.
Use permission sets only when a subset of users need additional
permissions.
If a lot of people in a profile need that permission, then create a custom
profile and add permission directly to that profile.
Layer 2: Field-level-security
Even if John has access to objects, she still needs access to individual fields of each object. In
Salesforce, profiles also control field-level access.
An admin can provide read and write permissions for individual fields. An admin can also set a field
to hidden, completely hiding the field to that user.
This is where record-level security comes in. Salesforce provides five ways to share records with
others and access others’ records.
Organization-wide defaults (OWD) control the default behavior of how every record of a given
object (for example, Accounts) is accessed by users who do not own the record. For example:
If OWD for Accounts is Private, it means Maria can only see records she is a owner of.
If OWD for Accounts is Read/Write, it means anyone can read and update (but not delete) the
record
3.2 Record -level-security: role hierarchies
Record-level security lets you give users access to some object records, but not others. The owner
has full access to the record. In a hierarchy, users higher in the hierarchy always have the same
access to users below them in the hierarchy.
In our case, the admin needs to add Maria to the appropriate role within Maria’s user
Sharing Rules for particular sets of users, to give them access to records they don’t own or can’t
normally see.
if John wants to share records with her peers in the service executive teams She can use sharing
rules.
If sharing rules and manual sharing don’t give you the control you need, you can use Apex
managed sharing. Apex managed sharing allows developers to programmatically share custom
objects. When you use Apex managed sharing to share a custom object, only users with the “Modify
All Data” permission can add or change the sharing on the custom object’s record, and the sharing
access is maintained across record owner changes
helper.js: JavaScript functions that can be called from any JavaScript code in a component’s
bundle
design: File required for components used in Lightning App Builder, Lightning pages, or
Community Builder.
SVG: Custom icon resource for components used in the Lightning App Builder or Community
Builder.
@api: To expose a public property, decorate it with @api. Public properties define the API for a
component. An owner component that uses the component in its markup can access the component’s
public properties. Public properties are reactive. If the value of reactive property changes, the
component’s template rerenders any content that references the property.
@track: To track a private property’s value and rerender a component when it changes,
decorate the property with @track. Tracked properties are also called private reactive properties.
@wire: To read Salesforce data, Lightning web components use a reactive wire service. When
the wire service provisions data, the component rerenders. Components use @wire in their JavaScript
class to specify a wire adaptor or an Apex method.
Ans:-To control when the method invocation occurs (for example, in response to clicking a button), call
the method imperatively. When you call a method imperatively, you receive only a single response.
Compare this behavior with @wire , which delegates control to the framework and results in a stream of
values being provisioned.
In the following scenarios, you must call an Apex method imperatively as opposed to using @wire .
To call a method that isn’t annotated with cacheable=true , which includes any method that
inserts, updates, or deletes data.
To control when the invocation occurs.
To work with objects that aren’t supported by User Interface API, like Task and Event.
To call a method from an ES6 module that doesn’t extend LightningElement
Strategic CRM
Operational CRM
Analytical CRM
Collaborative CRM
Example
It is similar to how a developer would use Map i.e. Trigger.NewMap on Case Object
would be similar to Map<Id, Case>. Trigger.NewMap allows a developer to select
specific records if needed.
Trigger.NewMap cannot be used in all Trigger events. It can only be used in the
following:
After Insert
Before Update
After Update
After Undelete
Example
The statement will run only 1 time and fetch subject of all Cases related to the
account records in the map:
for(Case c: cLst ){
//iterate over list and do some action
c.Subject = 'This case is being updated by trigger logic.';
*other logic......
}
}
When to use Trigger.New vs Trigger.NewMap
Use trigger.new when you want to iterate over a list and especially if the records
haven’t committed to the database as you wouldn’t have the IDs of the records yet.
However, as we noted above, trigger.new can be used in most before and after
events.
In contrast, use trigger.newmap when you have a specific use case where you have
a need to get a specific record based on a known ID etc, if you wish to not process
all records in the list.
Application events are used to communicate any change in the component to a broader audience. Any
component who has registered for this event will get a notified.
To use Component Event API we use the below syntax