Salesforce Interview Questions with Answers Part 66

Salesforce Interview Questions with Answers Part 66

1. Which Special characters need to be escaped in package.xml in Salesforce ANT deployment?
You need to escape the below

1. & – ampersand
2. &lt; – less than symbol( < )
3. &gt; – greater than symbol( > )
4. &quot; – quote
5. &apos; – apostrophe

2. Composite Request in Salesforce

1. Executes a series of REST API requests in a single call.
2. The response bodies and HTTP statuses of the requests are returned in a single response body.
3. The entire request counts as a single call toward your API limits.

The request body contains an allOrNone flag that specifies how to roll back errors. If true, entire request is rolled back. If false, the remaining sub-requests that don’t depend on the failed sub-requests are executed. In either case, the top-level request returns HTTP 200 and includes responses for each sub-request.

Controls whether the API collates unrelated subrequests to bulkify them (true) or not (false).
When subrequests are collated, the processing speed is faster, but the order of execution is not guaranteed (unless there is an explicit dependency between the subrequests).
If collation is disabled, then the subrequests are executed in the order in which they are received. Use this field if you have dependencies between your subrequests and you need to control the order of execution. If you don’t have an explicit dependency between your subrequests, then set collateSubrequests to true.
Check this for more information –
3. Difference between Application Event and Component Event

The major difference between application and component event is that component event is used in child to parent components and application event can be used through out the application

Component Event:

A change in a child component can be communicated to the parent component via component event.

Application Event:

Components which have registered for this event will get notified.

Reference Link –

Always try to use a component event instead of an application event, if possible. Component events can only be handled by components above them in the containment hierarchy so their usage is more localized to the components that need to know about them. Application events are best used for something that should be handled at the application level, such as navigating to a specific record. Application events allow communication between components that are in separate parts of the application and have no direct containment relationship.

4. Different between Composite and Batch in Composite Resources

In a subrequest’s body, you specify a reference ID that maps to the subrequest’s response. You can then refer to the ID in the url or body fields of later subrequests by using a JavaScript-like reference notation.

allOrNone flag is available for roll back option.

Subrequests are independent, and you can’t pass information between them. Subrequests execute serially in their order in the request body.

If a batch request doesn’t complete within 10 minutes, the batch times out and the remaining subrequests aren’t executed.

5. Automated Process User in Salesforce

Below run under the Automated Process entity
1. Platform event triggers/flows/process.
2. Approval Process Knowledge Actions.

can use getSessionId() both synchronously and asynchronously. In
asynchronous Apex (Batch, Future, Queueable, or Scheduled Apex), this
method returns the session ID only when the code is run by an active,
valid user. When the code is run by an internal user, such as the
automated process user or a proxy user, the method returns null.

As a best practice, ensure that your code handles both cases(Internal/External Users and Automated Process User).

With the introduction of API version 41.0, “Automated Process User” was made available.

Sample Class:
public class Sample {
    public static void fetchAutomatedUser() {
        System.debug( [ SELECT Id, Name, Alias FROM User WHERE Name = ‘Automated Process’ ] );


Code to Execute for testing:

If the API version of the Apex Class is 41 and above, the SOQL returns values.
If the API version of the Apex Class is 40 and below, the SOQL doesn’t return any value.

Profile Name with UserInfo.getProfileId() is null:

api version 41.0 there are 2 internal users which are exposed in test
class context. These users does not have normal profiles which is
resulting in the error.

6. How to get URL Parameters in Visualforce Page?

Help Article –

Sample Code:
<apex:page >   

7. How to do Callouts from Queueable Interface?

Use Database.AllowsCallouts.
public class SampleQueueable implements Queueable, Database.AllowsCallouts {} 

8. Composite Graph in Salesforce

Composite Graph in Salesforce is similar to Composite Request. But, this has higher limit. Powerful API request to avoid multiple API calls to Salesforce.
Regular composite requests allow you to execute a series of REST API requests in a single call. And you can use the output of one request as the input to a subsequent request.
Composite graphs extend this by allowing you to assemble a more complicated and complete series of related objects and records.
Composite graphs also enable you to ensure that the steps in a given set of operations are either all completed or all not completed. This avoids requiring you to check for a mix of successful and unsuccessful results.
Regular composite requests have a limit of 25 subrequests. Composite graphs increase this limit to 500. This gives a single API call much greater power.

9. How to abort Apex Jobs using Apex in Salesforce?

Use System.abortJob( ‘<JobID>’ ) to abort the job.
To get the JobId, use the “AsyncApexJob” object. Add proper WHERE condition to the SOQL to find the Job Ids.

10. Chat Button Type in Salesforce

1. Automated Invitation

a. Small window Pops up in the screen to start the Chat.
2. Chat Button
a. Doesn’t popup.

11. Binary and Numeric Prediction Salesforce
Binary predictions refer to yes/no predictions. Output will be a score and not a boolean. Score provides the likelyhood.
Example: Lead Scoring, Opportunity Scoring.
A binary outcome is an outcome variable that has only two text values, such as win-lose, pass-fail, or retain-churn. A story that represents a classification use case has a binary outcome variable.

Numeric predictions refer to predicting a number.
Example: Sales revenue prediction.

12. Securing Lightning Web Components

1. Locker
LWC uses Lightning Locker, a powerful security architecture for Lightning components that enhances security by isolating Lightning components in separate namespaces. 
2. LWC offers its own built-in security features, such as sanitization of malformed HTML code and blocking Content Security Policy (CSP)-incompatible code.
Load Assets Correctly
To import a third-party JavaScript or CSS library, use the platformResourceLoader module.

Blocking Inline Script
As part of our CSP implementation, LWC applications inside of Salesforce are blocked from loading an inline script, or calling a script from a template error or event handler. 

Filtering a Dynamic Script
To aid developers with building complex applications on the Salesforce ecosystem, dynamic script evaluation through eval() is enabled.
Add Third-Party APIs to Allowlist
In order to add third-party APIs to an allowlist, you must first add them to CSP Trusted Sites. This option can be found under Setup in your Salesforce org.

13. @api Read only in LWC
When a component decorates a field with @api to expose it as a public property, it should set the value only when it initializes the field. After the field is initialized, only the owner component should set the value. A component should treat values passed to it as read-only. To trigger a mutation for a property value provided by an owner component, a child component can send an event to the parent. If the parent owns the data, the parent can change the property value, which propagates down to the child component via the one-way data binding.

14. Wire Service in LWC
In the wire adapter’s configuration object, prefix a value with $ to reference a property of the component instance. The $ prefix tells the wire service to treat it as a property of the class and evaluate it as this.propertyName. The property is reactive. If the property’s value changes, new data is provisioned and the component rerenders.

We call the wire service reactive in part because it supports reactive variables, which are prefixed with $. If a reactive variable changes, the wire service provisions new data. We say “provisions” instead of “requests” or “fetches” because if the data exists in the client cache, a network request may not be involved.

Decorate a Property with @wire
Wiring a property is useful when you want to consume the data or error as-is.
If the property decorated with @wire is used as an attribute in the template and its value changes, the wire service provisions the data and triggers the component to rerender. The property is private, but reactive.
The property is assigned a default value after component construction and before any other lifecycle event. The default value is an object with data and error properties of undefined. Therefore, you can access the property’s value in any function, including functions used by the template or used as part of the component’s lifecycle.

Decorate a Function with @wire
Wiring a function is useful to perform logic whenever new data is provided or when an error occurs. The wire service provisions the function an object with error and data properties, just like a wired property.
The function is invoked whenever a value is available, which can be before or after the component is connected or rendered.

15. Adding Contacts to Case Team Member in Salesforce

Leave a Reply