Friday, October 17, 2014

Developer Interview Question and Answer Part 1? Apex Interview Questions.

Q). What is Apex in Salesforce?

• Apex is a procedural scripting language in discrete and executed by the Force.com platform.
• It runs natively on the Salesforce servers, making it more powerful and faster than non-server code, such as JavaScript/AJAX.
• It uses syntax that looks like Java
• Apex can written in triggers that act like database stored procedures.
• Apex allows developers to attach business logic to the record save process.
• It has built-in support for unit test creation and execution.


Apex provides built-in support for common Force.com platform idioms, including:
• Data manipulation language (DML) calls, such as INSERT, UPDATE, and DELETE, that include built-in DmlException handling


• Inline Salesforce Object Query Language (SOQL) and Salesforce Object Search Language (SOSL) queries that return lists of sObject records


- Looping that allows for bulk processing of multiple records at a time
- Locking syntax that prevents record update conflicts
- Custom public Force.com API calls that can be built from stored Apex methods
- Warnings and errors issued when a user tries to edit or delete a custom object or field that is referenced by Apex

Note: Apex is included in Unlimited Edition, Developer Edition, Enterprise Edition, and Database.com

Apex vs. Java: Commonalities
• Both have classes , inheritance, polymorphism, and other common OOP features.
• Both have the same name variable, expression, and looping syntax.
• Both have the same block and conditional statement syntax.
• Both use the same object, array, and comment notation.
• Both are compiled, strongly-typed, and transactional.


Apex vs. Java: Differences
• Apex runs in a multi-tenant environment and is very controlled in its invocation and governor limits.
• To avoid confusion with case-insensitive SOQL queries, Apex is also case-insensitive.
• Apex is on-demand and is compiled and executed in cloud.
• Apex is not a general purpose programming language, but is instead a proprietary language used for specific business logic functions.
• Apex requires unit testing for development into a production environment.

Force.com Apex Code Developer’s Guide

Q). What is Visualforce in Salesforce?

Visualforce is the component-based user interface framework for the Force.com platform. The framework includes a tag-based markup language, similar to HTML. Each Visualforce tag corresponds to a coarse or fine-grained user interface component, such as a section of a page, or a field. Visualforce boasts about 100 built-in components, and a mechanism whereby developers can create their own components.
• Visualforce pages can react differently to different client browsers such as those on a mobile or touch screen device.
• Everything runs on the server, so no additional client-side callbacks are needed to render a complete view.
• Optional server-side call outs can be made to any Web service.


Visualforce is a Web-based framework that lets you quickly develop sophisticated, custom UIs for Force.com desktop and mobile apps. Using native Visualforce markup and standard Web development technologies such as HTML5, CSS, JavaScript, and jQuery, you can rapidly build rich UIs for any app.
http://wiki.developerforce.com/page/User_Interface
Visualforce Developer’s Guide

Q). Apex code Execution Governors and Limits

Apex-Governer-limits
Apex-Governer-limits
This link should have more information about Apex code Execution Governors and Limits,
http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_gov_limits.htm

Q). Apex Data Types

Apex primitive data types include
- String
- Blob (for storing binary data)
- Boolean
- Date, DateTime and Time
- Integer, Long, Decimal, Double
- ID (Force.com database record identifier)
– Example:
• DateTime dt = System.now() + 1;
• Boolean isClosed = true;
• String sCapsFirstName = ‘Andrew’.toUpperCase();

Apex sObject Types
- Sobject (object representing a Force.com standard or custom object)
– Example:
• Account acct = new Account(); //Sobject example

Apex has the following types of collections
- Lists
- Maps
- Sets
– Example:
• List myList = new List();
• myList.add(12); //Add the number 12 to the list
• myList.get(0); //Access to first integer stored in the List

Enums
• Enum (or enumerated list) is an abstract that stores one value of a finite set of specified identifiers.
• To define an Enum, use enum keyword in the variable declaration and then define the list of values.
• By creating this Enum, you have created a new data type called Season that can be used as any other data type.
- Example:
• public enum Season {WINTER, SPRING, SUMMER, FALL}

Q). Variables

Local variables are declared with Java-style syntax.
For example:
Integer i = 0;
String str;
Account a;
Account[] accts;
Set s;
Map<ID, Account> m;

Q). Static Methods and Variables

• Class methods and variables can be declared as static. Without this keyword, the default is to create instance methods and variables.
• Static methods are accessed through the class itself, not through an object of the class:


Example:
public class blogReaders {
public static boolean firstScript = false;
}
• Static methods are generally utility methods that do not depend on an instance. System methods are static.
• Use static variables to store data that is shared with in the class.
– All instances of the same class share a single copy of static variables.
– This can be a technique used for setting flags to prevent recursive

Q). What is the use of static variable?

When you declare a method or variable as static, it’s initialized only once when a class is loaded. Static variables aren’t transmitted as part of the view state for a Visualforce page.
Static variables are only static within the scope of the request. They are not static across the server, or across the entire organization.

Q). Final variables

• The final keyword can only used with variables.
– Classes and methods are final by default.
• Final variables can only be assigned a value once.
– This can either be at assigned a value once.
• When defining constants, both static and final keywords should be used.
Example: public static final Integer =47;

Q). Difference between with sharing and without sharing in salesforce

By default, all Apex executes under the System user, ignoring all CRUD, field-level, and row-level security (that is always executes using the full permissions of the current user).
without sharing:
Enforcing the User’s Permissions, Sharing rules and field-level security should apply to the current user.
For example:
public with sharing class sharingClass {
// Code here
}

without sharing:
Not enforced the User’s Permissions, Sharing rules and field-level security.
For example:
public without sharing class noSharing {
// Code here
}

Enforcing the current user’s sharing rules can impact: (with sharing)
SOQL and SOSL queries – A query may return fewer rows than it would operating in system context.
DML operations – An operation may fail because the current user doesn’t have the correct permissions. For example, if the user specifies a foreign key value that exists in the organization, but which the current user does not have access to.

For More info Click Here:

Q). Class Constructors

• A constructor is a special method used to create(or instantiate) an object out of a class definition.
– Constructors never have explicit return types.
– Constructors have the same name as the class.
• Classes have default, no-argument, public constructor if no explicit constructors is defined.
– If you create a constructor that takes arguments and still want a noargument constructor, you must explicitly define one.
• Constructors can be overloaded, meaning you can have multiple constructors with different parameters, unique argument lists, or signatures.
• Constructors are called before all other methods in the class.

For Example:
public class TestObject2 {
private static final Integer DEFAULT_SIZE = 10;
Integer size;
//Constructor with no arguments
public TestObject2() {
this(DEFAULT_SIZE); // Using this(…) calls the one argument constructor
}
// Constructor with one argument
public TestObject2(Integer ObjectSize) {
size = ObjectSize;
}
}
New objects of this type can be instantiated with the following code:
TestObject2 myObject1 = new TestObject2(42);
TestObject2 myObject2 = new TestObject2();

Q). Class Access Modifiers

• Classes have different access levels depending on the keywords used in the class definition.
global: this class is accessible by all Apex everywhere.
• All methods/variables with the webService keyword must be global.
• All methods/variables dealing with email services must be global.
• All methods/variables/inner classes that are global must be within an global class to be accessible.

public: this class is visible across you application or name space.
private: this class is an inner class and is only accessible to the outer class, or is a test class.
• Top-Level (or outer) classes must have one of these keywords.
– There is no default access level for top-level classes.
– The default access level for inner classes is private.

protected: this means that the method or variable is visible to any inner classes in the defining Apex class. You can only use this access modifier for instance methods and member variables.
To use the private, protected, public, or global access modifiers, use the following syntax:
[(none)|private|protected|public|global] declaration




8 comments:

Unknown said...

TalScout is a video interviewing platform for both job seekers, & the employers. Simplifing talent hiring process with automated screening, virtual campus hiring online interviewing platform

Sakthi Murugan said...

I was searching for the better blog on Sales force CRM techniques to understand what CRM is and what is the use? Your blog is the right one I found to get depth knowledge. Thanks for sharing your wonderful ideas.
Regards
Salesforce Administrator 211 Training in Chennai
Salesforce Developer 401 Training in Chennai

Unknown said...

You made some good points here. I did a search on the Salesforce Developer and found most people will agree with this. Also Visit this site for to learn more about Salesforce Developer Online Training.

srinithya said...

Useful blog,admin. Share more questions with answers.
Salesforce Training in Chennai | Salesforce Training

Hema Malini said...

Nice post. Thanks for posting the blog
jsp interview questions
c++ interview questions
salesforce interview questions

Satyabrata Panda said...

Thanks to Admin for Sharing such useful Information. I really like your Blog. Addition to your Story here I am Contributing 1 more Similar Story UI Developer Interview Questions for Experienced Professionals.

Anonymous said...

Thanks, this is generally helpful.
Still, I followed step-by-step your method in this salesforce developer training
salesforce developer certification
salesforce developer course
salesforce developer training India

Anonymous said...

This is a very nice one and gives in-depth information. I am really happy with the quality and presentation of the article. I’d really like to appreciate the efforts you get with writing this post. Thanks for sharing.
Java course in Kolkata

Post a Comment

 
| ,