Salesforce Apex Interview Questions and Answers
1. What are the access modifiers in the apex?
Answer: If you do not specify an access modifier, the method or variable is private. This means that the method or variable is visible to any inner classes in the defining Apex class, and to the classes that extend the defining Apex class.
2. What are the reference variables in apex?
Answer: Passing Parameters By Reference and By Value in Apex. … “In Apex, all primitive data type arguments, such as Integer or String, are passed into methods by value. This means that any changes to the arguments exist only within the scope of the method. When the method returns, the changes to the arguments are lost.
3. In which object Roles are stored?
Answer: UserRole
4. What is the on-Demand process?
Answer: The on-demand process is nothing but “pay for what you use” policy.
We can subscribe to what we want and pay-as-you-go model.
5. Will the Flow supports the nullification mechanism?
Answer: Yes , flows support bulk records processing also.
6. If you organization Workflow’s limit is over and if you want to write a workflow immediately and it critical, what will you do?
Answer:
1. De-activate any workflows and create it using trigger and then do the new workflow.
or
2. Go for Schedule apex or trigger to achieve this workflow.
7. What is an alternative for workflow?
Answer: Process Builder or Flows or Trigger or Schedule apex or
8. What is the use of isNew()?
Answer: Checks whether the record is newly created.
9. What is the difference between List and Set?
Answer: Another significant difference between List and Set in Java is order. A list is an Ordered Collection while Set is an unordered Collection. List maintains the insertion order of elements, which means any element which is inserted before will go on the lower index than any element which is inserted after.
10. Data loader? and which format it will support?
Answer: Data loader is a tool to manage bulk data. It will support the .csv format of Excel.
11. What are the Disadvantages of using Batch Apex processing?
Answer:
Disadvantages of batch processing:
- It runs asynchronously, which can make it hard to troubleshoot without some coded debugging, logging, and persistent stateful reporting. It also means that it’s queued to run, which may cause delays in starting.
- There’s a limit of 5 batches in play at any time, which makes it tricky to start batches from triggers unless you are checking limits.
If you need access within execute() to some large part of the full dataset being iterated, this is not available. Each execution-only has access to whatever is passed to it, although you can persist class variables by implementing Database.stateful. - There is still a (fairly large) limit on total Heap size for the entire batch run, which means that some very complex logic may run over, and need to be broken into separate batches.
12. How many users have you supported?
Answer: Number of users in the Salesforce organization. It helps the recruiter to understand your scalability.
13. In which object all email templates are saved?
Answer: email template
14. What is Salesforce sites?
Answer: Used to show data from our organization for public view.
15. Explain The Apex Data Manipulation Language (DML) Operations?
Answer: Use data manipulation language (DML) operations to insert, update, delete, and restore data in a database.
You can execute DML operations using two different forms:
Apex DML statements, such as:
insertSObject[]
Apex DML database methods, such as:
Database.SaveResult[] result = Database.Insert(SObject[])
While most DML operations are available in either form, some exist only in one form or the other.
The different DML operation forms enable different types of exception processing:
Use DML statements if you want any error that occurs during bulk DML processing to be thrown as an Apex exception that immediately interrupts control flow (by using try. . .catch blocks). This behavior is similar to the way exceptions are handled in most database procedural languages.
Use DML database methods if you want to allow the partial success of a bulk DML operation: If a record fails, the remainder of the DML operation can still succeed. Your application can then inspect the rejected records and possibly retry the operation. When using this form, you can write code that never throws DML exception errors. Instead, your code can use the appropriate results array to judge success or failure. Note that DML database methods also include a syntax that supports thrown exceptions, similar to DML statements.
16. In which object all Account Team Members are added?
Answer:AccountTeamMember
17. Auto-response rules and Escalation rules(for which objects are mandatory)?
Answer: Case and Lead.
18. What is Documenting Salesforce.com in Apex class files?
Answer: I have used apexDoc for a while and we are starting to roll it out more fully for our use at my organization. It is open source software and so you could always contribute some updates for it: What features are you wanting to add to it that it doesn’t have (just to give a flavor)?
In answer to your questions:
- I don’t think anybody has successfully managed to do this. There is an idea of the ideas exchange for it to be done but it seems to gain very little support.
- Theoretically, it should be pretty easy as the apex is a Java DSL. Have you tried running Doxygen and if so what errors does it throw up?
- I use Apex Doc to generate some basic output and then have a little script tied in to copy across custom CSS and things. It isn’t perfect but it does the small amount we need at the moment.
I believe the IDE is being open-sourced at some time in which case I would imagine the antlr grammar file would become available which may help you out.
I know it is not really an answer for what you wanted to hear per se, but sadly it’s all we have atm (and I would love a nicer documentation generator!!) Learn Salesforce Training Online From Real-Time Experts
19. In which object all Opportunity Team Members are added?
Answer: OpportunityTeamMember
20. Difference between REST and SOAP AP I’S?
Answer: Varies on records that can be handled.
21. In Which object all Apex Pages are stored?
Answer: ApexPage
22. What are the uses of the tag?
Answer: A component that provides support for invoking controller action methods directly from JavaScript code using an AJAX request. A component must be a child of a component. Because binding between the caller and is done based on parameter order, ensure that the order is matched by the caller’s argument list.
Unlike, which only provides support for invoking controller action methods from other Visualforce components, defines a new JavaScript function which can then be called from within a block of JavaScript code.
Note: Beginning with API version 23 you can’t place inside an iteration component and so on. Put them after the iteration component, and inside the iteration put a normal JavaScript function that calls it.
This tag supports the following attributes:
Action: The action method invoked when the action function is called by a JavaScript event elsewhere in the page markup. Use merge-field syntax to reference the method. For example, action=”{!save}” references the save method in the controller. If an action is not specified, the page simply refreshes.
Focus: The ID of the component that is in focus after the AJAX request completes.
Id: An identifier that allows the action function component to be referenced by other components in the page.
Immediate: A Boolean value that specifies whether the action associated with this component should happen immediately, without processing any validation rules associated with the fields on the page. If set to true, the action happens immediately and validation rules are skipped. If not specified, this value defaults to false.
Name: The name of the JavaScript function that, when invoked elsewhere in the page markup, causes the method specified by the action attribute to execute. When the action method completes, the components specified by the reRender attribute are refreshed.
Onbeforedomupdate: The JavaScript invoked when the onbeforedomupdate event occurs–that is when the AJAX request has been processed, but before the browser’s DOM is updated.
incomplete: The JavaScript invoked when the result of an AJAX update request completes on the client.
Rendered: A Boolean value that specifies whether the component is rendered on the page. If not specified, this value defaults to true.
ReRender: The ID of one or more components that are redrawn when the result of the action method returns to the client. This value can be a single ID, a comma-separated list of IDs, or a merge field expression for a list or collection of IDs.
Status: The ID of an associated component that displays the status of an AJAX update request. See the action status component.
timeout: The amount of time (in milliseconds) before an AJAX update request should time out.
23. What is creating a debug log for users?
Answer: Track code.
24. What are Workarounds for Missing Apex Time?format() Instance Method?
Answer: You could just split the DateTime format() result on the first space – does that give you what you’re looking for?
public String myDateFormat(DateTime dt) {
String[] parts = dt.format().split(‘ ‘);
return (parts.size() == 3) ? (parts[1] + ‘ ‘ + parts[2]) : parts[1];
produces
6:38 PM
for me in English (United States), and
18:42
in French(France).
UPDATE: As to logic points out, the above method is not very robust – some locales may include spaces in the date or time portion of the format, and the ordering is not consistent. This second attempt assumes that the date and time are separated by zero or more spaces, but handles spaces within the two portions, and either ordering of date and time. The only assumption made is that the formatted Date is contained within the formatted Time:
public String my date format(DateTime dt) {
return dt.format().replace(dt.date().format(), ”).trim();
It seems to work fine for Hebrew, Vietnamese & Korean, as well as English and French.
25. How cases are created?
Answer: Email to Case and Web to Case
26. What is the difference between With Sharing and Without Sharing?
Answer: For example, if a method is defined in a class declared with sharing is called by a class declared without sharing, the method will execute with sharing rules enforced. … For example, if the class is called by another class that has sharing enforced, then sharing is enforced for the called class.
27. What is after undelete?
Answer: While retrieving from the recycling bin
28. In which object all Approval process are stored?
Answer: Approval
29. Is there an average method for apex math?
Answer: Unfortunately the standard math methods only include simpler operations (i.e. those that work on a single, or two values), so it looks as though you’ll have to roll your own method.
Of course, the number of script statements executed will be proportional to the length of the list, so of the lists are ever of a fixed size it could be worth using a macro to generate the addition part for you:
Int sum = i[0] + i[1] + … i[n];
Doing so would only count for one statement, but you’ll only need this if governor limits are of concern which is often not a worry.
If governor limits aren’t an issue you could create a function along these lines:
Skip code block
Integer[] myInts = new Integer[]{1, 2, 3, 4, 5, 6, 7};
Integer total = 0;
Double Avg;
for (Integer i : myInts) {
total += i;
Avg = Double.valueOf(total) / myInts.size();
return Avg;
30. Will Trigger.new supports —>Insert, Will Trigger.Delete supports —>Delete?
Answer: Yes.
31. What is a constructor?
Answer: A constructor is a special method of a class or structure in object-oriented programming that initializes an object of that type. A constructor is an instance method that usually has the same name as the class, and can be used to set the values of the members of an object, either to default or to user-defined values.
32. What is the Inline visualforce page?
Answer: Having the page on pagelayout.
33. What is the Grammar for creating an Apex parser?
Answer: Keep an eye on Apex tooling API, which is used in the Developer console. This is supposed to be released to public access soon.
34. If his a child is a mandatory field in lookup and I m deleting Parent, will the child get deleted?
Answer: No.
35. What is the use of the static variables?
Answer: Static variables are used when only one copy of the variable is required. so if you declare variable inside the method there is no use of such variable it’s become local to function only.. Variables declared static are commonly shared across all instances of a class.
36. Junction object? when will we use it? If we delete the junction object what will happen?
Answer: For many to many relationships.
37. Does ‘default value’ do anything if the object is created through Apex?
Answer: New feature coming in the next release:
Foo__c f = Foo__c.sobjecttype.newSObject(
record typed, // can be null
true); // loadDefaultValues
38. Can we have V.F pages in page layout?
Answer: Yes.
39. What are Subjects?
Answer: An sObject is any object that can be stored in the Force.com platform database. These are not objects in the sense of instances of Apex classes; rather, they are representations of data that has or will be persisted. sObject is a generic abstract type that corresponds to any persisted object type.
40. How to create a standard object as a child to custom object(which is not possible thru standard away process, have to bypass this restriction)?
Answer: Create Lookup and make the lookup field mandatory.
41. Detect the current Logging Level in Apex?
Answer: Unfortunately, I don’t think there is a way to check the current logging level in APEX.
42. In a visual force page the save should ensure the data to be stored in current object as well as associated child object?
Answer: We have to use a Database.SavePoint and Database.Rollback for this situation.
43. What is Map in apex?
Answer: 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, subjects, user-defined types, and built-in Apex types.
44. What is the audit field, what is the purpose of the audit field?
Answer: Created By, Created Date, Last Modified By, and Last Modified Date are audit fields. Used to track when the changes are done to the records.
45. Call Apex class method on the fly (dynamically)?
Answer: While you can instantiate a class based on its name using the Type system class, you can’t dynamically locate a method and execute it. The best that you can do is to dynamically create an instance of a class that implements an interface and executes one of the methods on the interface.
There’s more information on the Type class and an example in the :
Apex Developer’s Guide
46. What do we need to do for extending the limit of creating only 2 M-D relationships for a custom object?
Answer: Create Lookup and make the lookup field mandatory.
47. Can we have duplicate Keys in Map?
Answer: You can’t have duplicate keys in a Map. You can rather create a Map<Key, List>, or if you can, use Guava’s Multimap. And then you can get the java.util.Map using the Multimap#asMap() method.
48. How to write javascript code for the save button?
Answer: We have to create the custom button and in that custom button, we have to write Javascript code.
49. How many objects we can store on the list?
Answer: You can store only one Object at a time. But you can store as many as records or instance of an object till you don’t hit Salesforce Heap size limit which is 6 MB for Developer Edition. So it will depend on data you are storing in List like how many fields and type of data you want to store in that list.
50. What are the attributes of the apex tag?
Answer: Attribute tag is used in creating components. ( Salesforce Online Training)