An Introduction to Exception Handling – SalesForce


It is a set of applications

  • A special type of encapsulation, in which we’ve member methods & prototypes


→ Return type name (list & saq of input declarations);

  • One basic reason why we need interface is because multiple inheritance is possible only through interfaces

→ Interfaces enforces a class to perform certain operations (actions)

→ The protocols b/w the class and interface is that the class must implement (define), all the method prototypes inside the interface

→ The actual technical reason behind creating an interface is not multiple inheritance. Its name and purpose behind interface is used by the operating system level services for the code

→ Providing OS level services to the code is done by Interface


→ Interface gives names and i/p


For interface

Interface name {



Class child implements name {

Features are mandatory to define the prototyped methods in the interface



Global interface calc {

Void add ();

Void sub ();


Class opers implements calc {

Return a+b;


Public integer sub () {

Return a- b ;

`                                               }


Public class test {

Public static test method void main () {

Opers op1 = new opers ();

Op1.add (5,4);

System. debug (‘ subtraction is ‘ +sub);



Exception Handling

Exception (fault) is an abnormal event that occurs generally after the execution of a program. It affects the normal program flow.

→It is run time error through which execution is stopped

→ Another name for run time error is exception error, there are two types of errors

  • Syntax error (or) Compile time
  • Runtime error (or) exception

→ A compile time (syntax) error occurs whenever we violate the syntax of the language

→ The only way to overcome this scenario is by changing the source code

→ In case of run time error this might occur not due to programming error but because of run time

→ Environment such as

  • Improper limits
  • Lack of resources // insufficient memory
  • Lack of connectivity

→ Such errors also stop the execution

→ In order to overcome run time errors and to continue with the execution of the programming language a mechanism is provided known as exception handling


It stores large volumes of information, there are three types of collections in sales force

  • List
  • Sat
  • Map


A collection of similar volumes

It is also re sizable


Provides values which are unique

It is also re sizable


Collection of pairs

Every pair is associated with a key that is associated with a value

Pair → <key, value>

  • Key → access the value  –>(Can be an integer, string, id only )
  • Value can be any type



Template class, here we have to fix the data type at run time

CREATION OF LIST:                                                            

  • List <string satud_names_new list <string> ();
  • Stud _ names.sige à count of values existing in the list

Input to the list:

  • Stud_names. Add (‘Ashok’);
  • Stud_names. Add (‘Pandu’)
  • Stud_names.remove (‘Ashok’);

Remove → clear only one record from the list

  • Stud_names.clear ();

Clear (); → content of the list will be cleared

  • Stud_ names. Add (i1)


Removes common values of stud_names and list:


There are four ways to display

  1. For loop
  2. While loop
  3. Do- while
  4. For – each


For ( integer IND = 0; IND < stud_names. Size ;

IND ++)


System.debug(stud_names [IND]);


In apex, we will work only for – each loop


For each

For (data type var_name : collection _name)


System. Debug (var_name);



For (string Sn: stud_names ) {

System.debug (Sn);


  • Means each string in that collection has to be displayed
  • Here, no need to specify starting & ending number and incrimination


Put (key, value) → for adding

Get (key) → for retrieving

List → we can work only for ‘subject’

Set → can’t work for subject this can work for primitive data types


If we have an ID, we can access any record

  • We can’t create table through Apex to the DB
  • We can’t drag table through Apex to the DB
  • We can’t alter a table through Apex to the DB
  • These statements are called DDL statements
  • We can’t apply DDL statements through Apex
  • We can give DML operations as input through Apex to the data base


We can undelete a data from the sales force within a span of 45 days.



Sales force object query language (SOQL) is used to retrieve the data by using “select” stmt

In SOQL search only for table


Sales force object search language (SOSL) is used to retrieve the data from the database, for this we used “find” stmt

Here to search the entire database

Select work with records (Table)

Find work with text based search across from the DB returns field only but not records


We’ve to set ‘save point’ to particular points and not for all

  • Most recently saved will come out first
  • Max save points are 10

Governor limits:

  • Governor limits are the rules which enforced restrictions at run time with respect to organizations


  • No. of SOQL queries : 100
  • No. of query rows :50000
  • No. of SOSL queries : 20
  • No. of DML statements :150
  • DML rows : 10000
  • No. of script statements: 200000
  • Maximum heap size : 3000000
  • No. of callouts : 10
  • No. of email invocations :10
  • No. of field describes : 100
  • No. of record type describes : 100
  • No. of child relationships : 100
  • No. of PICK lists, describes : 100
  • No. of future calls : 10


Public with sharing class call test 1 {

Public static test method void main () {

List < string > stud_names = new list < string > ();

Stud_names. Add (‘Ashok’);

Stud_names. Add (‘Yadav’);

Stud_names. Add (‘Buddi’);

For (string str: stud_names) {

System. Debug (‘name; ‘ +str);


List <Book_c> prog_books =new list <books _c>();

Prog_books = « ______ »;

Book_c Sb = new book_c ();

Sb.name = ‘apex prog’;

Sb.price _ c = 200;

Sb. Author_c = ‘krishna’;

Try {

Insert prog_books;


Catch (exception e) {

System.debug (‘exceeded limit’);


Prog-books = « ______ »;

For (Book_c b: prog_books){

System.debug (b. price_c);

System.debug (b. author_c);




Enroll for Live Instructor Led Online SalesForce Training

0 Responses on An Introduction to Exception Handling – SalesForce"

Leave a Message

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

Copy Rights Reserved © Mindmajix.com All rights reserved. Disclaimer.