An Introduction to Exception Handling – SalesForce

Exception Handling is a method in Salesforce that allows us to handle undesirable exceptions or problems in our code without interrupting the flow. Read on to learn more about salesforce’s exception handling with detailed examples.

Interface

It is a set of applications

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

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

Interested in mastering SalesForce? Enroll now for FREE demo on SalesForce Course
Interfacing

→ Interface gives names and i/p

Syntax:

For interface
Interface name {
Prototypes
}
Class child implements name {
Features are mandatory to define the prototyped methods in the interface
}

Eg:

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);
}
}

MindMajix Youtube Channel

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

Checkout Salesforce Interview Questions

Collections

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

  • List
  • Sat
  • Map

List:
A collection of similar volumes
It is also re sizable

Set:
Provides values which are unique
It is also re sizable

Map:
Collection of pairs
Every pair is associated with a key that is associated with a value
Pair →
Key → access the value  –>(Can be an integer, string, id only )
Value can be any type

Syntax For List:

Syntax

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

Creation Of List:                                                            

  • List ();
  • 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:

Output From The List:

There are four ways to display
1.For loop
2.While loop
3.Do- while
4.For – each

Explore SalesForce Sample Resumes! Download & Edit, Get Noticed by Top Employers!Download Now!

 

For:
For ( integer IND = 0; IND < stud_names. Size ;
IND ++)
{
System.debug(stud_names [IND]);
}
In apex, we will work only for – each loop

Syntax:
For each
For (data type var_name : collection _name)
{
System. Debug (var_name);
}
Eg:
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

Map:
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
Combine the tables

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

Standard tables

SOQL:
Sales force object query language (SOQL) is used to retrieve the data by using “select” stmt
In SOQL search only for table

SOSL:
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

Save Point:

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

Limits:

  • 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

                       Check Out Salesforce Tutorials

Collection Program:

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 prog_books =new list ();
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

Mindmajix offers different Salesforce certification training according to your desire with hands-on experience on Salesforce concepts

Salesforce Administration TrainingSalesforce Lightning Training
Salesforce Advanced Developer TrainingSalesforce Developer Training
Salesforce IoT TrainingSalesforce App Builder Certification Training
Salesforce AppExchange TrainingSalesforce Service Cloud Training
and many more.. 

 

Job Support Program

Online Work Support for your on-job roles.

jobservice

Our work-support plans provide precise options as per your project tasks. Whether you are a newbie or an experienced professional seeking assistance in completing project tasks, we are here with the following plans to meet your custom needs:

  • Pay Per Hour
  • Pay Per Week
  • Monthly
Learn MoreGet Job Support
Course Schedule
NameDates
Salesforce TrainingNov 19 to Dec 04View Details
Salesforce TrainingNov 23 to Dec 08View Details
Salesforce TrainingNov 26 to Dec 11View Details
Salesforce TrainingNov 30 to Dec 15View Details
Last updated: 04 Apr 2023
About Author

Arogyalokesh is a Technical Content Writer and manages content creation on various IT platforms at Mindmajix. He is dedicated to creating useful and engaging content on Salesforce, Blockchain, Docker, SQL Server, Tangle, Jira, and few other technologies. Get in touch with him on LinkedIn and Twitter.

read less
  1. Share:
Salesforce Articles