Part 7: Salesforce Apex Interview Questions

61. What are different types of collections in Apex?

Lists–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.

Sets–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.

Maps–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.

62. What are different primitive datatypes used in Apex?

String,Integer,Boolean,Decimal,Date,Datetime

63. Is Apex Case sensitive?

Unlike Javascript, Lightning Webcomponents/Lightning Components, Apex is case Insensitive.

64. How are constants defined in Apex?

Constants can be defined using the final keyword.

Ex: static final Integer PRIVATE_INT_CONST = 200;

65. What does SOQL stand for and explain with an Example?

SOQL stands for Salesforce Object Query Language. This is used to query a list of records from the database.SOQL statements evaluate to a list of sObjects, a single sObject, or an Integer for count method queries.

List<Account> accnt = [SELECT Id, Name FROM Account WHERE Name = 'salesforce'];

66. What are the Governor Limits on SOQL Queries?

Maximum number of SOQL queries issued in Synchronous(Trigger or Realtime) call is 100

Maximum number of SOQL queries issued in Asynchronous(Batch Apex, Queuable, Future) call is 200

67. How many records can be retrieved through a SOQL query?

Total number of records retrieved by SOQL queries is 50000

68.  What does SOSL stand for and explain with an Example?

SOSL stands for Salesforce object Search Language. SOSL always returns List of List of Sobject records.

SOSL statements evaluate to a list of lists of sObjects, where each list contains the search results for a particular sObject type. The result lists are always returned in the same order as they were specified in the SOSL query. If a SOSL query does not return any records for a specified sObject type, the search results include an empty list for that sObject.

List<List<SObject>> searchList = [FIND 'map*' IN ALL FIELDS RETURNING Account (Id, Name), Contact, Opportunity, Lead];

69.What is the consideration for selective SOQL Query Criteria?

  • A query is selective when one of the query filters is on an indexed field and the query filter reduces the resulting number of rows below a system-defined threshold. The performance of the SOQL query improves when two or more filters used in the WHERE clause meet the mentioned conditions.
  • The selectivity threshold is 10% of the first million records and less than 5% of the records after the first million records, up to a maximum of 333,333 records. In some circumstances, for example with a query filter that is an indexed standard field, the threshold can be higher. Also, the selectivity threshold is subject to change.

70. Define Aggregate functions in Salesforce?

Aggregate functions in SOQL, such as SUM() and MAX(), allow us to roll up and summarize data in a query. Aggregate functions become a more powerful tool to generate reports when you use them with a GROUP BY clause. For example, you could find the average Amount for all your opportunities by campaign.

AggregateResult[] groupedResults= [SELECT CampaignId, AVG(Amount) FROM Opportunity  GROUP BY CampaignId];
for (AggregateResult ar : groupedResults)  {
    System.debug('Campaign ID' + ar.get('CampaignId'));
    System.debug('Average amount' + ar.get('expr0'));
}




sfdclightning

Related post