function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
sfdc startsfdc start 

interview question pz answer .........important

1. what is severity in salesforce....................?
2. what are error message in vf page and one example...?
3.what is exception handling ? when it occurs ? how can rectify that type of errors....with small example...?
NagendraNagendra (Salesforce Developers) 
Severity:Severity is the enum that determines how severe a message is, and summary is the String used to summarize the message. 

Message(severity, summary):

Creates a new instance of the ApexPages.Message class using the specified message severity and summary.

Signature
public Message(ApexPages.Severity severity, String summary)
Parameters
Severity
Type: ApexPages.Severity
The severity of a Visualforce message.
Summary
Type: String
The summary Visualforce message.

Severity for error message is defined when we add message in to page using our code. See code below for different severity:
 
if(acc.name == '' || acc.name == null)
       ApexPages.addmessage(new ApexPages.message(ApexPages.severity.FATAL,'Please enter Account name'));

      if(acc.AccountNumber == '' || acc.AccountNumber == null)
       ApexPages.addmessage(new ApexPages.message(ApexPages.severity.ERROR,'Please enter Account number'));

      if(acc.phone == '' || acc.phone == null)
       ApexPages.addmessage(new ApexPages.message(ApexPages.severity.WARNING,'Please enter Account phone'));

      if(acc.site == '' || acc.site == null)
       ApexPages.addmessage(new ApexPages.message(ApexPages.severity.INFO,'Please enter Account site'));

      if(acc.industry == '' || acc.industry == null)
       ApexPages.addmessage(new ApexPages.message(ApexPages.severity.CONFIRM,'Please enter Account industry'));

User-added image

Example for Error Message in Visual Force Page:Refer to the below link
http://www.sfdcpoint.com/salesforce/show-error-message-visualforce-page/

Exception Handling:

Exception:An exception is a special condition that changes the normal flow of program execution. That is, it's when something bad happens that the program can't deal with during execution.

What happens when exception occurs:When an exception occurs, and you haven't written any code to deal with it, it's called 'unhandled.' First, an unhandled exception brings processing to a halt. If the code that has processed so far contained any Database Manipulation Language (DML) statements, those statements will be rolled back completely.

The system then notifies the running User of the problem. If you run into an exception in Apex code while using the standard user interface, a red text message will appear at the top of the screen showing you the text of the unhandled exception. If the exception was caused by a custom field validation error and you've set that to show next to the field that caused the error, a red message will show up there.

The system will then try to notify the developer of the code in question that there has been an unhandled exception. An email will get sent to the developer with the Organization Id and User Id of the running user, as well as the exception message.

If you run into an exception that occurred in Apex code while using the standard user interface, an error message appears on the page showing you the text of the unhandled exception as shown below:

User-added image

Catching Exceptions:Uncaught exceptions are less than ideal. They're kind of like the Windows "blue screen of death"--not the most graceful end to a program's functioning you could imagine. The error message the end user sees might not make much sense to them, and who knows what kind of state the data is in. This section looks at how to catch the exceptions, so that you can insert some code to handle it in some way. The following section will look at techniques for handling the exception.

The good news is that Apex allows for you to handle your exceptions, and write code to gracefully recover from an error. Apex uses the Try, Catch, Finally construct common to many other programming languages. You "try" to run your code. If there is an exception, you "catch" it and can run some code, then you can "finally" run some code whether you had an exception or not.
You can have multiple Catch blocks to catch any of the 20 different kinds of exceptions. If you use a generic exception catcher, it must be the last Catch block.

Here's what a try-catch-finally block looks like:
try{
     //Your code here
} catch (ListException e) {
     //Optional catch of a specific exception type
     //Specific exception handling code here
} catch (Exception e) {
     //Generic exception handling code here
} finally {
     //optional finally block
     //code to run whether there is an exception or not
}
How do I handle exceptions that I've caught:

As I mentioned above, the developer of the code gets notified of uncaught exceptions. The running user gets a notice as well, either in the standard user interface, or if they are using a SOAP API application, they'll get the notice if the developer has chosen to expose the message.
When you catch exceptions, you lose the default notification mechanisms that exist with uncaught exceptions—you'll need to build your own. Here are some ways in which you can handle exceptions that you catch, and notify folks of the problem.

DML:
Exceptions can occur in DML statements. For example, you may try to insert a record without a required field. TheaddError() method can be called on a record or a field and will prevent the DML operation from committing.
Here's an example:
For more information on exception handling and examples please refer to the below link:
http://sfdcsrini.blogspot.com/2014/04/what-is-exception-handling-in-apex.html

Please mark it as best answer if it helps you.

Best Regards,
Nagendra.P