Advanced Salesforce Apex Interview Questions And Answers

38 Advanced Salesforce Apex Interview Questions And Answers For Experienced 2019 from Codingcompiler. Test your Salesforce Apex knowledge by answering these tricky interview questions on Apex. Let’s start learning Salesforce Apex interview questions and prepare for Salesforce interviews. All the best for your future and happy learning.

Salesforce Apex Interview Questions

  1. What is Apex?
  2. Explain about Apex syntax?
  3. Does Apex support DML operations?
  4. Is Apex strongly typed language?
  5. Does Apex supports unit tests?
  6. When should developers choose Apex?
  7. What are the different data types in Apex?
  8. What are the common methods of data types in Apex?
  9. What are the limitations of Apex?
  10. Does Apex support switch statements?
  11. What types of statements we can use in Apex?
  12. What types of collection does Apex supports?
  13. How can you declare List/Map/Set in Apex?
  14. What are the different types of Apex code development tools?
  15. What is Force.com Developer Console?

Related Salesforce Interview Questions

Salesforce Apex Interview Questions And Answers

 

1) What is Apex?

A) Apex is a proprietary language developed by Salesforce.com. According to official definitions, Apex is a strongly typed, object-oriented programming language that allows developers to execute traffic and transaction control statements on the Force.com platform server while calling the Force.com API.

 

2) Explain about Apex syntax?

A) It has a Java-like syntax and is like a database stored procedure. It enables developers to add business logic to most system events, including button clicks, related record updates, and Visualforce pages.

 

3) Does Apex support DML operations?

A) Apex has built-in support for DML operations such as INSERT, UPDATE, DELETE, and DML exception handling. It supports inline SOQL and SOSL query processing, returning a set of sObject records.

 

4) Is Apex strongly typed language?

A) Apex is a strongly typed language. It uses direct reference to architectural objects such as sObject, and any invalid references that fail if they are deleted or if they are of the wrong data type will fail quickly.

 

5) Does Apex supports unit tests?

A) Apex provides built-in support for unit test creation and execution, including test results indicating how much code is covered, and which parts of the code can be more efficient.

 

6) When should developers choose Apex?

A) Apex should be used when we can’t use pre-built and existing out-of-the-box functionality to implement complex business functions.

 

7) What are the different data types in Apex?

A) Different data types available in Apex are,

  1. Basic data type (Integer/Boolean/String)
  2. Boolean
  3. Date/Datetime/Time
  4. ID (18 bits and 15 bits, can be converted to and from String)
  5. Integer/Long/Double/Decimal
  6. String
  7. Blob
  8. Object
  9. Enum (enumeration type)
  10. sObjects ( sObjects/Account/Position_c, etc. )
  11. Collection (list, set, map, etc.)
  12. User-defined and system custom objects
  13. Null

 

8) What are the common methods of data types in Apex?

A) Common methods of data types

  • Date: addDays()/dayOfYear()/daysBetween()/month()/toStartOfMonth()/year()
  • Datetime: addHours()/hourGmt()/minute()
  • String: compareTo()/contains()/equals()/indexOf()/length()/split()/substring()/toUpperCase()/toLowerCase()
  • Enum: ordinal()View location
  • sObject: addError(), parent object_r
  • List (ordered): add()/remove()/clear()/clone()/deepClone()/get/set/isEmpty()/size()/sort()
  • Set (unordered, not repeated): add()/addAll()/clear()/clone()contains()/cnstainsAll()/isEmpty()/remove/removeAll()/retainAll()/size()
  • Map(key-value): clear()/clone()/deepClone()/constiansKey()/get/set/isEmpty()/keySet()/put/putAll/remove/size/values

 

9) What are the limitations of Apex?

A) Apex limitations

The Apex programming language is saved and runs in the cloud – the Force.com multi-tenant platform. Apex is tailored to data access and data manipulation on the platform, allowing you to add custom business logic to system events. While it provides many benefits for business process automation on the platform, it is not a general-purpose programming language.

Therefore, Apex cannot be used for:

  1. Render elements in the user interface instead of error messages
  2. Change standard features – Apex can only prevent features from happening or add other features
  3. Create a temporary file
  4. Generating threads

 

10) Does Apex support switch statements?

A) Apex does not support switch statements.

Interview Questions on Salesforce Apex

 

11) What types of statements we can use in Apex?

A) Like java, Apex must end with a semicolon; it can be one of the following types:

  • Assignment, such as assignment to a variable
  • Condition (if-else)
  • Loop: Do-While, While, For
  • Locking
  • Data manipulation language (DML)
  • Transaction control
  • Method call
  • Exception handling (try catch)

 

12) What types of collection does Apex supports?

A) Apex has the following types of collections:

  1. Lists (arrays)
  2. Maps
  3. Sets

 

13) How can you declare List/Map/Set in Apex?

A) Apex is similar to Java’s List/Map/Set declaration method, except that it allows direct assignment when declaring:

  • List<Integer> My_List = new List<Integer>(){1,2,3};
  • Set<String> My_String = new Set<String>{‘a’, ‘b’, ‘c’};
  • Map<Integer, String> My_Map = new Map<Integer, String>{1 => ‘a’, 2 => ‘b’, 3 => ‘c’};

 

14) What are the different types of Apex code development tools?

A) In all versions, we can use the following three tools to develop code:

  • Force.com Developer Console
  • Force.com IDE
  • Code editor in the Salesforce user interface

 

15) What is Force.com Developer Console?

A) The Developer Console is an integrated development environment with a set of tools for creating, debugging, and testing applications in your Salesforce organization.

 

16) What is sObject in Apex?

A) This is a special data type in Salesforce. It is similar to a table in SQL and contains fields similar to those in SQL. There are two types of sObjects: Standard and Custom.

 

17) Can you write simple example code for sObject in Apex?

A) Here is the sample code for sObject,

//Declaring an sObject variable of type Account

Account objAccount = new Account();

//Assignment of values ​​to fields of sObjects

objAccount.Name = ‘ABC Customer’;

objAccount.Description = ‘Test Account’;

System.debug(‘objAccount variable value’+objAccount);

//Declaring an sObject for custom object APEX_Invoice_c

APEX_Customer_c objCustomer = new APEX_Customer_c();

//Assigning value to fields

objCustomer.APEX_Customer_Decscription_c = ‘Test Customer’;

System.debug(‘value objCustomer’+objCustomer);

 

18) What in Enum in Apex?

A) An enumeration is an abstract data type that stores a value of a finite set of specified identifiers. You can define an enumeration using the keyword Enum. Enumerations can be used as any other data type in Salesforce.

 

19) Can you write sample example code for enumeration in Apex?

A) Here is the sample example code for enum,

Assuming you want to declare the possible name of the compound, then you can do this:

//Declaring enum for Chemical Compounds

Public enum Compounds {HCL, H2SO4, NACL, HG}

Compounds objC = Compounds.HCL;

System.debug(‘objC value: ‘+objC);

Advanced Salesforce Interview Questions And Answers

 

20) Difference between database methods and DML statements?

A) Differences between database methods and dml statemetns,

DML statement: Some updates are not allowed. For example, if there are 20 records in the list, all records will be updated or not updated.

Database method: Allow partial updates. You can specify the parameter to true or false in the Database method, true to allow partial updates, false to not allow the same.

 

DML statement: You cannot get a list of success and failure records.

Database method: You can get a list of success and failure records, as we saw in the examples.

 

DML Statement Example: insert listName;

Database Method Example: Database.insert(listName, False), where false means partial updates are not allowed.

 

21) What are SOSL and SOQL methods in Salesforce Apex?

A) SOSL:

Searching for text strings across entire objects and fields will be done using SOSL. This is the Salesforce object search language. It has the ability to search for specific strings on multiple objects.

The SOSL statement evaluates a list of sObjects, each of which contains search results for a particular sObject type. The result list is always returned in the same order as specified in the SOSL query.

SOQL:

This is almost the same as SOQL. You can use it to get only one object record from an object. You can write a nested query and get the record from the parent or child object you want to query.

 

22) What is Apex Call?

A) The Apex call refers to the process of executing the Apex class. The Apex class can only be executed when called by one of the following methods:

  • Triggers and anonymous blocks
  • The trigger is called for the specified event.
  • Asynchronous Apex
  • Schedule the Apex class to run at specified intervals or run a batch job.
  • Web service class
  • Apex Email Service Class
  • Apex Web Services, which allows you to expose your methods through SOAP and REST web services.
  • Visualforce controller
  • Apex email service to handle inbound email.
  • Call Apex using JavaScript
  • The Ajax toolkit is used to invoke the Web service methods implemented in Apex.

 

23) What are Apex Triggers?

A) Apex triggers are similar to stored procedures that are executed when a specific event occurs. It is executed before and after the event is logged.

Syntax: Trigger triggerName on ObjectName ( trigger_events ) { Trigger_code_block }   

 

24) What is Batch Apex?

A) Batch Apex is asynchronously executed Apex code designed to handle large numbers of records and has more flexibility in terms of regulator limits than synchronous code.

 

25) When do you use batch processing of Apex?

A) When you want to process a large number of records every day, or at specific intervals, you can go to Batch Apex.

Also, when you want an operation to be asynchronous, you can implement batch processing. Batch Apex is exposed as an interface that must be implemented by the developer. Batch jobs can be called programmatically at runtime using Apex. Batch Apex operates on small batch records, overwriting the entire recordset, and breaking the process down into manageable blocks of data.

 

26) How do you debug the code in Apex?

A) In Apex, we have some tools for debugging. One of them is the system.debug() method, which prints the value and output of the variable in the debug log.

There are two tools that you can debug:

  • Developer console
  • Debug log

 

27) What is Force.com Migration Tool?

A) This tool is used for script deployment. You must download the Force.com migration tool and then you can perform a file-based deployment. You can download the Force.com migration tool and then perform a script deployment.

 

28) What is SOQL loop?

A) This type of for loop is used when we don’t want to create a List and traverse the return recordset of a SOQL query directly. We will delve deeper into SOQL queries in the next chapter. Now, just remember that the list of records and fields it returns is given in the query.

Syntax:

for (variable : [soql_query]) { code_block }

or:

for (variable_list : [soql_query]) { code_block }

 

29) What is Blob in Apex?

A) Blob: Binary storage type, generally used to receive uploaded attachment documents, etc.

 

30) What is ID type in Salesforce Apex?

A) ID: This type is unique to Salesforce and is used to represent the 18-bit id identifier of salesforce’s sObject.

Salesforce Apex Interview Questions And Answers For Experienced

 

31) How do you convert a string to an Integer type?

A) Convert a string to an Integer type, valueOf(), for example:

Integer.valueOf(’12’); //12;

Integer.valueOf(’12a’); //throw TypeException

 

32) How do you convert long type is converted to int method?

A)  Long type is converted to int method, intValue(), for example:

Long curLong = 71;

Integer myInt = curLong.intValue(); //71

 

33) What does contains method do in Apex?

A) contains() to see if the string contains a method for a specified string.

E.g:

String str1 = ‘abc’;

String str2 = ‘a’;

str1.contains(str2); //true

 

34) Can you explain some string methods which were used in your projects?

A) I worked with various string methods in my previous projects, they are,

1) startsWith()- whether the string begins with a given string.

2) endsWith()- whether the string ends with a given string.

3) toUpperCase()- which is capitalized.

4) toLowerCase()- which is changed to lowercase.

5) length()- to find the length of the string.

6) replace()- replaces the string matching content.

7) split()- splits the string into a List collection according to the specified string.

8) trim()- remove the spaces before and after the string.

9) indexOf()- which gets the index of the first match of the string with the given string, and -1 if there is no match.

10) lastIndexOf()- which gets the subscript of the last match of the string with the given string, and no.

11) substring()- intercepts the string between the given subscripts in the string.

 

35) Can you explain about few commonly used date type methods?

A) Date and DateTime methods are many, I will mention a few commonly used methods here,

1) newInstance(), create a Date.

E.g:

Date d = Date.newInstance(2019,1,15); //2019-1-15

 

2) day(), get the day of the date.

E.g:

Date d = Date.newInstance(2018,9,12);

d.day(); //12

 

3) month(), get the month in the date.

E.g:

Date d = Date.newInstance(2018,9,12);

d.month(); //9

 

4) year(), get the year in the date.

E.g:

Date d = Date.newInstance(2019,9,12);

d.year(); //2019

 

5) daysBetween(), get the number of days between the two dates.

E.g:

Date startDay = Date.newInstance(2018,9,12);

 

Date endDay =Date.newInstance(2018,10,2);

 

startDay.daysBetween(endDay); //20

 

6) addDays(), add the number of days.

E.g:

Date d = Date.newInstance(2018,9,12);

d.addDay(3); //2018-9-15

 

7) getTime(), which is the number of milliseconds elapsed from 1970-01-01 00:00:00 to the calculation time.

E.g:

DateTime d = Date.newInstance(2018,9,12,8,0,0);

d.getTime(); //1473681600000

 

36) What are the characteristics of Apex?

A) Apex has the following characteristics

 

1) Integration

  •   Insert, update and delete, etc., are included in the DmlException, called in the DML language.
  •   The return is sObject type recode list, tandem Salesforce Oject Query Language (SOQL) and Salesforce Object Search Language (SOSL) query
  •   Multiple records can be processed simultaneously
  •   Encounter repeated data updates automatically avoid, and lock
  •   The saved Apex method can be rebuilt, and can call the generic Force.com API
  •   The referenced Apex custom object or custom project will be warned when it is edited or deleted.

2) More convenient to use

Apex’s variables and syntax components, modules, conditional declarations, loop declarations, representations of objects and arrays are all based on JAVA. Considering that Apex is easier to understand when importing new features, the Force.com platform can run more efficiently and develop Apex.

3) Data pointing

And developers in the database server in the same essentials conduct multiple transactions declared by the database stored procedure, on the Force.com platform server, Apex multiple queries and DML statements are designed to a session. As with other database stored procedures, Apex does not support execution on the user interface.

4) Very clear

The object name and project name in Apex are directly referenced to the schema object and are strongly typed languages. When this reference is not available when the reference is not found, a compilation error will occur immediately. In order to prevent the referenced Apex code from being deleted, all the standard items in the master data and the class associations are saved.

5) Autonomy

The Apex language is based on the implementation, control and control of the Force.com platform.

6) Multi-tenancy

Like other Force.com platforms, Apex is implemented in a rented environment. To accommodate this environment, Apex’s real-time engine is designed to avoid code that interferes with each other, and the shared code is not occupied by a single tenant. When the code that violates the rule fails to execute, an error message that is easy to understand is displayed.

7) can be automatically upgraded

In Apex, the upgrade of other parts of the Force.com platform does not need to be directly described. Because the compiled code is saved as master data in the platform, Apex has also been upgraded as part of the release.

8) Easy to test

In Apex, how much is the code covered, is it more effective than a certain part of the code? They are all expressed in the test results, etc., and can be tested and executed as a single unit. In SalesForce, all of the individual tests were performed before the platform upgrade, and it was confirmed that all standard Apex code was executed as expected.

9) Have version management

The version of the Apex code change can be saved in the Force.com   API. According to this, to maintain normal operation. Apex includes Performance Edition, Unlimited Edition, Developer Edition, Enterprise Edition and Database.com.

 

37) What are the conditions for using Apex?

A) SalesForce is a combination of various functions that provide CRM (customer relation manage) applications. Or, SalesForce is a custom application that integrates the corresponding organization. However, organizations have parts that do not support their own complex business processes. In the SalesForce platform, senior administrators and developers can package a variety of methods. Among these methods are Apex, VisualForce, and Soap APIs.

1) Apex – Use Apex for the following occasions

  • Web service
  • Create a mail service
  • Detect multiple complex objects
  • Create complex business processes that are not supported in workflow
  • Make a custom transaction (not just a single record, object, the logic of the transaction)

2) Visualforce

Visualforce uses a tag-based tagging language that allows developers to develop user interfaces while developing efficient ones. With VisualForce, you can do the following

Build other multiple steps such as weChat

Develop custom controllers independently between applications

Navigation patterns and inherent rule definitions for the most appropriate and effective application interaction.

For details, please refer to the book “VisualForce Handwriting” on the SalesForce website.

3) SOAP API

The need to manage only one record type at a time, managing transactions (savepoint settings and rollback of changes, etc.) does not use the standard SOAP API call without adding functionality to the composite application.

 

38) What are the functions of Apex?

A) Apex is compiled, saved and executed on the Force.com cloud platform. When the developer saves the Apex code, the application server of the cloud platform translates the abstract command settings into assembly code that can be recognized by the background according to the Apex real-time translator, and then saves the commands as a metadata to the cloud platform.

The end user clicks the button and accesses the VisualForce screen to execute the Apex code. The application server of the cloud platform obtains the compiled command from the metadata, passes it to the cloud through the real-time program translator, and then returns the running result. The end user does not have to care about the requirements of the cloud platform and the difference in program execution time.

Must Read Books on Salesforce Apex

Related Interview Questions And Answers

  1. JDBC Interview Questions
  2. Java Servlet Interview Questions
  3. Java Web Interview Questions
  4. Java Multithreading Interview Questions
  5. Java IO Interview Questions
  6. Java String Interview Questions
  7. Java Collections Interview Questions
  8. Java Exceptions Interview Questions
  9. Java OOPS Interview Questions
  10. Core Java Interview Questions
  11. JSF Interview Questions
  12. JSP Interview Questions
  13. JPA Interview Questions
  14. Spring Framework Interview Questions
  15. Spring Boot Interview Questions
  16. Core Java Multiple Choice Questions
  17. 60 Java MCQ Questions And Answers
  18. Aricent Java Interview Questions
  19. Accenture Java Interview Questions
  20. Advanced Java Interview Questions For 5 8 10 Years Experienced
  21. Core Java Interview Questions For Experienced
  22. GIT Interview Questions And Answers
  23. Network Security Interview Questions
  24. CheckPoint Interview Questions
  25. Page Object Model Interview Questions
  26. Apache Pig Interview Questions
  27. Python Interview Questions And Answers
  28. Peoplesoft Integration Broker Interview Questions
  29. PeopleSoft Application Engine Interview Questions
  30. RSA enVision Interview Questions
  31. RSA SecurID Interview Questions
  32. Archer GRC Interview Questions
  33. RSA Archer Interview Questions
  34. Blockchain Interview Questions

 

Leave a Reply

Your email address will not be published. Required fields are marked *