Salesforce Developer Interview Set 1
Salesforce Developer Interview Set 1
I am sharing all the questions I have faced in interviews and detail answers
for it to make learning easy.
Parent is rendered:
You see the list of available flights, complete with details and options to
select. The parent component is fully rendered and visible to you.
ConnectedCallback:
Purpose: To perform tasks that require the component to be in the DOM,
such as data fetching or event listener registration.
When Called: When the component is inserted into the DOM.
DisconnectedCallback:
Purpose: To perform cleanup tasks, such as removing event listeners or
cancelling subscriptions.
When Called: When the component is removed from the DOM.
RenderedCallback:
Purpose: To perform post-render tasks, such as interacting with the DOM
or third-party libraries.
When Called: After every render of the component.
By Smriti Sharan (sfdcamplified)
renderedCallback()
renderedCallback() is unique to Lightning Web Component. DOM is
created after the connectedCallback and before the renderedCallback.
renderedCallback() method is called after render() method.
This method is invoked when component is completely rendered,Basically
when all the elements on the component are inserted. This method called
is after every render of the component. This hook flows from child to
parent.
Note: As this method called after every render of the component, so
we need to be careful, if we want to perform some operation is specific
conditions like performing one time operation, use a private boolean
property like hasRendered to track whether renderedCallback() has been
executed.
errorCallback()
It Captures errors that may happen in all the child components lifecycle
hooks. This method is unique to LWC.
It has two parameters error and stack.The error argument is a JavaScript
native error object, and the stack argument is a string.
If there is error in child then parent handles the error but if there is error in
parent then it is shown in the UI.
By Smriti Sharan (sfdcamplified)
connectedCallback() vs renderedCallback()?
connectedcallback()
• The connected callback is executed when the component is inserted
into DOM. this is similar to init handler in aura.
• The connectedCallback() hook can fire more than once. For example,
if you remove an element and then insert it into another position, such
as when you reorder a list, the hook fires several times.
• The execution flow of connectedCallback is parent to child. So you
cannot access child elements in the connectedCallback, because
they are not inserted yet.
• Don’t update a wire adapter configuration object property in
renderedCallback()
• Don’t update a public property or field in renderedCallback()
renderedcallback()
This gets called when the component is rendered.
Example
// Query to get the total amount of each Account
List<AggregateResult> results = [
SELECT AccountId, SUM(Amount) totalAmount
FROM Opportunity
GROUP BY AccountId
];
For Example :
string myTestString = ‘TestName’ ;
List<sObject> sl = Database.query(SELECT Id,Name FROM
myCustomObject__c WHERE Name=: myTestString);
By Smriti Sharan (sfdcamplified)
Dynamic SOQL can be invoked by Database.query(query_string); where
query_string is the query generated at runtime.
Imperative Calls
Imperative calls involve explicitly calling an Apex method within JavaScript
logic, in response to an event or user action.
16.What is database.stateful?
Database.Stateful interface is used in Batch Apex to maintain state across
multiple transactions within the same batch job. Normally, each execution
of the execute method in a Batch Apex job runs in its own transaction.By
implementing the Database.Stateful interface, we can retain the values of
instance variables between these transactions.
Common use cases include aggregating results, keeping counters, or
accumulating a list of records to process at the end of the batch job.
Example:Suppose we want to count the number of Opportunity records
processed in a batch job. We can use Database.Stateful to maintain a
counter across transactions.
Parallel Mode
In parallel mode, Salesforce processes multiple batches of records
simultaneously. This can lead to faster data loading but may cause issues
with record locking.
Example, while Account A is being updated, the system might also try to
insert Contact C1 and C2. If Account A is locked due to the update, the
insert operation for Contacts will fail.
Serialization Mode
In serialization mode, Salesforce processes one batch of records at a time,
in a specific order. This mode ensures that updates and inserts are handled
sequentially, avoiding record locking issues.
34.You want to query contacts and ensures only readable fields are
returned. How will you do that in apex?
List<Contact> contacts = [SELECT Id, Email, Phone FROM Contact];
SObjectAccessDecision decision =
Security.stripInaccessible(AccessType.READABLE, contacts);
List<Contact> secureContacts = decision.getRecords();
2. Logic-less Triggers: Keep the trigger logic minimal. Use the trigger only
to delegate processing to handler classes or methods. This makes the
trigger more readable and easier to maintain.
3. Bulkify Your Code :Ensure code can handle multiple records at once.
Salesforce processes triggers in batches of up to 200 records, so code
should efficiently handle collections of records rather than processing one
record at a time.
4. Avoid SOQL and DML in Loops: Never put SOQL queries or DML
operations inside loops. This practice helps avoid hitting Salesforce
governor limits. Instead, perform these operations outside the loop by using
collections.
9. Optimize your SOQL queries to retrieve only the necessary fields and
records. This practice helps improve performance and stay within governor
limits.