0% found this document useful (0 votes)
8 views14 pages

Interview Question

The document outlines a custom rollup summary code for Salesforce, detailing the execution order of triggers, operations that do not invoke triggers, and additional considerations for trigger frameworks. It also discusses Lightning Web Components (LWC) communication methods, such as custom events and Lightning Message Service (LMS), as well as how to perform HTTP callouts without coding. Furthermore, it explains sharing rules in Apex, including with sharing, without sharing, and inherited sharing, along with examples of scheduling classes in batch processing.

Uploaded by

jayu.crystals08
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views14 pages

Interview Question

The document outlines a custom rollup summary code for Salesforce, detailing the execution order of triggers, operations that do not invoke triggers, and additional considerations for trigger frameworks. It also discusses Lightning Web Components (LWC) communication methods, such as custom events and Lightning Message Service (LMS), as well as how to perform HTTP callouts without coding. Furthermore, it explains sharing rules in Apex, including with sharing, without sharing, and inherited sharing, along with examples of scheduling classes in batch processing.

Uploaded by

jayu.crystals08
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

Custom rollup summary code.

trigger ContactTrigger on Contact (after insert, after update, after delete, after undelete) {

Set<Id> accountIds = new Set<Id>();

if([Link]){

for(Contact con:[Link]){

if([Link] != null){

[Link]([Link]);

} else {

if([Link]){

for(Contact con:[Link]){

if([Link]([Link]).AccountId != [Link]){

[Link]([Link]);

else {

for(Contact con:[Link]){

if([Link] != null){

[Link]([Link]);

if(![Link]()){

List<Account> accList = [SELECT Id, Number_of_Contacts__c, (SELECT Id FROM Contacts)


FROM Account WHERE Id IN : accountIds];

if(![Link]()){

List<Account> updateAccList = new List<Account>();

for(Account acc:accList){

Account objAcc = new Account(Id = [Link], Number_of_Contacts__c = [Link]());

[Link](objAcc);

if(![Link]()){

update updateAccList;

Order of execution :

[Link] record.

[Link] the request came from a standard UI edit page, Salesforce runs system validation to check the
record for page layout-specific rules, field definition, and Maximum field length.

[Link] before record-triggered flows.

[Link] all before triggers.

[Link] most Custom validation.

[Link] duplicate rules.

[Link] the record to the database, but doesn’t commit yet.

[Link] all after triggers.

[Link] rules.

[Link] auto-response rules.

[Link] workflow rules. If there are workflow field updates,

- updates the record again.

- Due to Workflow field updates introducing new duplicate field values, executes duplicate rules
again.
- If the record was updated with workflow field updates, fires before update triggers and after update
trigger one more time (and only one more time), in addition to standard validations. Custom
validation rules are not run again.

[Link] rules.

[Link] these Salesforce Flow automations

Processes

Flows launched by processes

Flows launched by workflow rules (flow trigger workflow actions pilot)

[Link] record-triggered flows that are configured to run after the record is saved.

[Link] entitlement rules.

[Link] the record contains a roll-up summary field or is part of a cross-object workflow, performs
calculations and updates the roll-up summary field in the parent record. Parent record goes through
save procedure.

[Link] the parent record is updated, and a grandparent record contains a roll-up summary field or is
part of a cross-object workflow, performs calculations and updates the roll-up summary field in the
grandparent record. Grandparent record goes through save procedure.

[Link] Criteria Based Sharing evaluation.

[Link] all DML operations to the database.

[Link] all after-commit logic.

sending email.

asynchronous Apex jobs

Asynchronous paths in record-triggered flows

What is part of the after commit logic?

[Link] email sends

[Link] Apex: @future methods

[Link] Sharing Rule processing (for >25,000 records)

[Link] Messages placed on queue

[Link] Index, such as Search Index

[Link] File Previews

[Link] of Platform Events (if configured)

Operations That Don’t Invoke Triggers


[Link] delete operations. Records that did not initiate a delete don’t cause trigger evaluation.

[Link] updates of child records that are reparented as a result of a merge operation

[Link] campaign status changes, Mass division transfers, Mass address updates, Mass approval
request transfers, Mass email actions

[Link] custom field data types

[Link] or replacing picklists

[Link] price books

[Link] a user’s default division with the transfer division option checked

[Link] account triggers don’t fire before or after a business account record type is changed to
person account (or a person account record type is changed to business account.)

[Link] triggers don’t fire on FeedItem when the LikeCount counter increases.

Additional Considerations

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. Please
implement Trigger framework for same.

LWC Custom event :

Child component :

import { LightningElement } from 'lwc';

export default class ChildComp extends LightningElement {

handleChange(event) {

[Link]();

const name = [Link];

const selectEvent = new CustomEvent('mycustomevent', {

detail: name

});

[Link](selectEvent);

}
}

Parent component :

<template>

<div class="slds-m-around_medium">

Value From Child : {msg}

<c-child-comp onmycustomevent={handleCustomEvent}></c-child-comp>

</div>

</template>

import { LightningElement , track } from 'lwc';

export default class ParentComponent extends LightningElement {

@track msg;

handleCustomEvent(event) {

const textVal = [Link];

[Link] = textVal;

LMS Example :

Lightning Message Service (LMS) is a communication framework provided by Salesforce that enables
effective communication between Lightning Web Components (LWC) and other components on a
Lightning page.

LMS is used to communicate with unrelated LWC component , aura and vf component.
LMS named lmsDemo :

Publisher component name lmsComponentA :


Subscriber component lmsComponentB :
Output :
There are 3 lwc component a, b and c. b is parent to c , a is parent to b. I want to send data from c to
a. how this can be done.

If we want to directly pass data from child c to grand parent a we can use custom event.

Component c (Child Component): Dispatch a custom event with the data you want to send. While
dispatching event give bubble and composed as true so that event can bubble up from target
component and composed as true will make sure the event passes the shadow boundary.

Component b (Intermediate Component): No changes needed as it will automatically pass the event
up.

Component a (Parent Component): Listen for the custom event and handle it.

How to make a callout without coding?

To make a call out without coding we have you make use of flow action named create http callout.

Flow -> add action -> create http callout

Add name and named credential


After that we need to specify method, url path and query parameters

Then add sample response.


Then click on save and provide input variables.

To handle error from http callout add decision block.


On success we can update account field as shown below by using update record block.

Types of sharing rule?

There two types of sharing rules , owner based and criteria based sharing rule.

Enforce FLS in LWC?

With sharing and without sharing in apex?

[Link]

Can we have multiple JS and HTML for single LWC component?

Yes we can have multiple HTML and JS file for single LWC component

HTL : [Link]

JS : [Link]
[Link]

Can we call schedulable class from batch class?

Yes, you can call a schedulable class from a batch class in Salesforce using [Link]('My
Scheduled Job', cronExpression, schedulableClassInstance); in execute method.

Here's how you can do it:


1. Define the Schedulable Class: Ensure you have a class that implements the Schedulable
interface.

apex

Copy code

public class MySchedulableClass implements Schedulable {

public void execute(SchedulableContext sc) {

// Your code here

2. Call the Schedulable Class from a Batch Class: You can schedule the schedulable class from
within the execute method of your batch class by using the [Link] method.

apex

Copy code

public class MyBatchClass implements [Link]<sObject>, [Link] {

public [Link] start([Link] bc) {

return [Link]([SELECT Id FROM Account]);

public void execute([Link] bc, List<sObject> scope) {

// Your batch processing code here

// Schedule the schedulable class

String cronExpression = '0 0 0 * * ?'; // Runs daily at midnight

MySchedulableClass schedulableClassInstance = new MySchedulableClass();

[Link]('My Scheduled Job', cronExpression, schedulableClassInstance);

public void finish([Link] bc) {

// Code to execute after batch completes

With sharing, without sharing and inherited sharing ?


System mode : In system mode, Apex code has access to all objects and fields— object permissions,
field-level security, sharing rules aren't applied for the current user. This is to ensure that code won’t
fail to run because of hidden fields or objects for a user.

User mode : User mode is nothing but running apex code by respecting user's permissions and
sharing of records. For example, logged in user does not have create permission and so he/she is not
able to create a record.

With sharing : The with sharing keyword enforces sharing rules (and not permissions) of the current
user. You have to explicitly set this keyword for the class because Apex code runs in system mode.

Example - Let's consider that the OWD for Account is private, no account records are owned by or
shared with an user 'u' and a "with sharing" class called MyClass is fetching account records in a list.
Now if class 'MyClass' is run by user 'u' then no records will be fetched. Remember that whether the
user 'u' is having full CRUD or having no CRUD record will not be fetched.

Without sharing : The 'without sharing' keyword is to ensure that the sharing rules (not
permissions) for the current user are not enforced.

Example - Let's consider that the OWD for Account is private, no account records are owned by or
shared with an user 'u' and a "without sharing" class called MyClass is fetching account records in a
list. Now if class 'MyClass' is run by user 'u' then account records will be fetched. Remember that
whether the user 'u' is having full CRUD or having no CRUD, records will be fetched.

WOS -> IS = A WOS , B WOS ;

IS - > WOS = A(if A is entry point in apex when ) WS, B WOS

WS -> IS = A WS , B WS

IS -> WS = A(if A is entry point in apex when ) WS, B WS

OS -> IS = A WOS , B WOS

WS -> OS = A WS , B WS (Here if we want B class to run in WOS then we have to explicitly mention B
as WOS)

WOS -> OS = A WOS, B WOS

WOS -> WS = A WOS, B WS

WS -> WOS = A WS, B WOS

If the class is used as the entry point to an Apex transaction, an omitted sharing declaration runs
as without sharing.

If the class is used as the entry point to an Apex transaction, inherited sharing ensures that the
default is to run as with sharing.

In addition the omitted sharing class behaves as with sharing when it is called from the Lightning
Web component. I have tried and tested this with the below code.

You might also like