Salesforce Interview Questions with Answers Part 60

1. USING SCOPE clause for SOQL
The new USING SCOPE clause for SOQL queries lets you limit results by filterScope.
SELECT column_name FROM table_name USING SCOPE filterScope_value

filterScope_value can take one of the following enumeration values: Everything, Mine, Queue, Delegated, MyTerritory, MyTeamTerritory or Team.

SELECT Name FROM Account USING SCOPE Everything

2. Why No assigned Id to record in Before Insert trigger
Id is assigned after committing to database. So, only in After Insert you will get the id of that record.
Since the record is not inserted/committed into the database, Id is not populated.

3. How to protect against SOQL injection vulnerabilities?
Static Query and Bind Variables
The first and most recommended method to prevent SOQL injection is to use static queries with bind variables. Consider the following query.
Static Query:

String query = ‘select id from contact where firstname =\’’+var+’\’’;
queryResult = Database.execute(query);

Using user input (the var variable) directly in a SOQL query opens the application up to SOQL injection. To mitigate the risk, translate the query into a static query like this one.
queryResult = [select id from contact where firstname =:var];

Another strategy to prevent SOQL injection is to use typecasting. By casting all variables as strings, user input can drift outside of expectation. By typecasting variables as integers or Booleans, when applicable, erroneous user input is not permitted.

Escaping Single Quotes
Another XSS mitigation option that is commonly used by developers who include user-controlled strings in their queries is the platform-provided escape function String.escapeSingleQuotes().

If you must use dynamic SOQL, use the escapeSingleQuotes method to sanitize user-supplied input. This method adds the escape character (\) to all single quotation marks in a string that is passed in from a user. The method ensures that all single quotation marks are treated as enclosing strings, instead of database commands.

Create a list of all “known good” values that the user is allowed to supply. If the user enters anything else, you reject the response.

Replacing Characters
A final approach for your tool belt is character replacement, also known as blacklisting. This approach removes “bad characters” from user input.

Check the below Example
'SELECT Id, AccountNumber, Name, Amount__c FROM Account WHERE IsActive = ' + var;
If someone enters "true AND AccountNumber = 100", they will get all info about Account with Account Number "100".
We can use the below code
This will remove all the whitespaces. So, that the query becomes invalid( SELECT Id, AccountNumber, Name, Amount__c FROM Account WHERE IsActive = trueANDAccountNumber=100 )

4. Organization value Vs. Profile Value Vs. User Value in hierarchical custom settings - Which takes precedence?
The hierarchy logic checks the organization, profile, and user settings for the current user and returns the most specific, or “lowest,” value. In the hierarchy, settings for an organization are overridden by profile settings, which, in turn, are overridden by user settings.

5. Lead Nurturing
Lead nurturing is triggering emails based on a person’s behavior or a preset time interval.

6. Differences Between Git and GitHub
Git and GitHub share a name and a mission, but they’re not the same thing. Distinguishing exactly where the line is drawn between Git and GitHub may take some time, and that's okay. You were introduced to each in the previous unit, but let's dig a little deeper to understand how they work together.

Git Is a Version Control Application
Simply put, Git is the application that keeps track of everything related to the changes on your project over time. Let’s start by defining a few key terms:

Repositories: A collection of source files used to compile your project.

Commits: A snapshot of your project as it existed at a specific point in time. You create commits as you work on your project to indicate points when you added and removed discrete units of work.

Branch: A series of commits that represent the changes in your project over time. Every repository has a default branch, which contains the production-ready version of your code. Create additional branches when you’re working on new features, fixing bugs, or making other changes to your project. These branches keep your experimental code separate from your tested production code.

Merge: The combined history of two or more branches. Most of the time, you’ll merge your feature branch into the default or deployed branch of the repository in order to move the features into production.

Tag: A pointer to a specific commit, which provides a persistent reference to an event. Typically, tags are used with semantic versioning to represent points when your application was released.

GitHub Is a Collaboration Platform
GitHub is a host for Git repositories with collaboration features that let you apply and test changes to your code. In Git terms, GitHub serves as a remote, giving developers an accessible source of truth for their shared work. In addition to having access to all of the Git data for your repository, GitHub has a few key terms of its own:

Issues:  Have general discussions about your project, make plans for new features, and discuss bugs. An issue is only a discussion, no actual changes to code take place here.

Pull requests:  A pull request is a package of commits you’re requesting to be merged into the default branch. A pull request provides a place to discuss the changes you’re proposing and invite other team members to comment and complete code reviews. Pull requests also help you see the result of automated tests and many other cool integrations.
GitHub is designed to provide a highly transparent and contextual environment for developers to do their best work.

In short, Git handles version control and GitHub handles collaboration.

7. Will Trigger.NewMap be available in Before Insert? 
No. Since the data is not yet committed to the database, Id won’t be available to hold in the map.

8. WhoId (Name) field iss not getting populated through apex in Event object in Salesforce?

When "Allow Users to Relate Multiple Contacts to Tasks and Events" is enabled, WhoId cannot be set through Apex.

Once the event is created, create EventRelation record.

EventRelation obj = new EventRelation( EventId = Event Id );
obj.RelationId = Contact/LeadId;
obj.IsParent = true;
obj.IsInvitee = false;
insert obj;

Create multiple EventRelation records to attach multiple Leads/Contacts to the Event.

9. Transfer Record permission in Profile in Salesforce
To transfer multiple accounts, campaigns, contacts, contracts, and custom objects:
Transfer Record AND Edit on the object type

To transfer multiple leads:
Transfer Leads OR Transfer Record AND Edit on leads

To transfer multiple cases:
Transfer Cases OR Transfer Record AND Edit on cases

OWD or Sharing Rules or Role Hierarchy won't work since Transfer Record override it.

10. How to relate Custom object and Field in Custom MetaData type in Salesforce?
Create Relationship field relating to Entity Definition for Object.
Create Relationship field relating to Field Definition for Field. While relating to field definition, Controlling Object will need relationship field to Entity Definition.

11. fieldsToNull in Salesforce API Call

Array of one or more field names whose value you want to explicitly set to null.
When used with update() or upsert(), you can specify only those fields that you can update and that have the nillable property. When used with create(), you can specify only those fields that you can create and that have the nillable or the default on create property.

For example, if specifying an ID field or required field results in a runtime error, you can specify that field name in fieldsToNull. Similarly, if a picklist field has a default value and you want to set the value to null instead, specify the field in fieldsToNull.

To reset a field value to null, you add the field name to the fieldsToNull array in the sObject. You cannot set required fields (nillable is false) to null.

        sObject objContact = new sObject();
        objContact.type = "Contact";
        // Set the value of LastName to null
        errorContact.fieldsToNull = new String[] { "LastName" };


HTTPS, which is a version of a website that encrypts data in transit, rather than HTTP which does not.

13. What is a debug log in Salesforce?
A debug log is a record of database operations, system processes, and errors for a designated transaction.
Each debug log cannot exceed 2 MB.
Each org can retain up to 50 MB of logs. Once limit is reached, the older logs will be overwritten.

14. How to allow Forecast manager and user to edit in Forecasts tab?
a. Enable manager adjustments
b. Enable owner adjustments

1. To let forecast managers adjust the amounts of their immediate subordinates and child territories, enable manager adjustments.
2. To let all forecast users adjust the amounts of their own forecasts, including the territory forecasts they own, enable owner adjustments.
3. From Setup, enter Profiles in the Quick Find box, and then select Profiles. Click Edit next to a profile, and then select Override Forecasts.

15. Quota in Salesforce Forecasting
A quota is a sales goal that’s assigned to a forecast user or territory. A manager’s quota equals the amount that the manager and team are expected to generate together. If you enable quotas, quota information appears on the forecasts page along with optional attainment percentages that show how well your team is doing.

16. How to automate product schedule to Opportunity Product in Salesforce?

17. Joined Report in Salesforce
A joined report can contain data from multiple standard or custom report types. You can add report types to a joined report if they have relationships with the same object or objects. For example, if you have a joined report that contains the Opportunities report type, you can add the Cases report type as well because both have a relationship with the Accounts object.

A joined report consists of up to five report blocks, which you add to the report to create multiple views of your data.

Each joined report has a principal report type. By default, the principal type is the first one added to the report. For example, if you create the joined report by selecting the Opportunities report type, and then add the Cases type, the Opportunities type is the principal report type. The principal report type controls how common fields are named. Some common fields have different names or appear in different sections in different report types.

When a joined report contains multiple report types, some fields are identified as common fields. A field is a common field if it’s shared by all report types or if all report types share a lookup relationship to the field. Common fields can be used to group report blocks. In Lightning Experience, common fields are identified by the Common Fields Icon icon. In Salesforce Classic, common fields appear in the Common Fields area in the Fields pane.

18. Smart Totaling in Reports in Salesforce
“Smart” totaling means that duplicate data is counted only once in any subtotal or total. Salesforce uses “smart” totaling when you run reports that include duplicate data in any of the columns chosen for summing or averaging.

For example, suppose an opportunity has two products, and you run the Opportunity Product Report with the total opportunity amount selected as a column to sum by. The amount appears twice in the details of the report, once for each product on the opportunity.

In this case, “smart” totaling correctly calculates any subtotals, grand totals, and averages, adding that opportunity amount only once.

For dashboard components, “smart” totaling isn't used. For example, in a dashboard table, the total displayed is simply the sum of the values listed in the table.

19. Report and List View runtimes vary
Salesforce has a caching system with respect to reports and list views that improves performance on queries that have been run recently. The data from recently run queries is stored in logical memory. The term for this is cached data. When data is cached, queries run quicker because reading from logical memory is faster than reading from a physical hard drive.

Note: The amount of time for which the queries are cached is dependent on a number of variables and may not always be consistent.

If the report is timing out, running it again may reduce the runtime and allow it to complete successfully.

Reasons why a report may run slowly include:
a. It is querying too many objects
b. It is dealing with intricate relationships.
c. It has too many fields.

20. Lightning Bolt for Salesforce
Lightning Bolt for Salesforce lets you quickly build and distribute industry-specific Lightning Bolt Solutions to jump-start new org capabilities. Save time by building once and then reusing. Whether it’s for your own org or you’re a consulting partner or ISV, you can reduce the time required to implement solutions and cut development costs.

A Lightning Bolt Solution combines one or more of the following.

1. Customized Lightning Community templates—A template includes a theme layout and CSS, along with pages, content layouts, and Lightning components. Instead of a full template, you can also export a single Community page with its content layout and components.
2. Flow categories—A flow category contains one or more flows, making it easy to group flows for related business processes.
3. Custom apps—Adding customized apps lets you create solutions tailored to your industry.

No comments:

Post a Comment