trigger TheTrigger on Account (before insert, after insert)
{
System.debug('-- Creating an exception -- '+(2/0));
}
Apex Class
public class DemoClass
{
public void demoMethod()
{
Try
{
System.debug('--Entered--');
Account acc = new Account(Name='Test');
insert acc;
System.debug('-account created --'+acc.Id);
Contact con = new Contact(LastName='TestCon');
insert con;
System.debug('--Contact created'+con.Id);
}
catch(Exception exe)
{
System.debug('created new error log');
}
}
}
trigger TheTrigger on Account (before insert, after insert)
{
try
{
System.debug('-- Throw an exception -- '+(2/0));
}
catch(Exception exe)
{
DemoClass.stopTheExecution=false;
}
}
Apex Class
public class DemoClass
{
Public Static Boolean stopTheExecution=true;
public void demoMethod()
{
Try
{
Savepoint sp = Database.setSavepoint();
Account acc = new Account(Name='Test');
insert acc;
if(stopTheExecution==false)
Database.rollback(sp);
Savepoint sp2 = Database.setSavepoint();
System.debug('--account created ?-- '+acc.Id);
Contact con = new Contact(LastName='TestCon');
insert con;
System.debug('--Contact created '+con.Id+ ' ====Static
variable== '+stopTheExecution);
if(stopTheExecution==false)
Database.rollback(sp2);
}
catch(Exception exe)
{
System.debug('Handle Exception or create error log');
}
}
}
000383729

We use three kinds of cookies on our websites: required, functional, and advertising. You can choose whether functional and advertising cookies apply. Click on the different cookie categories to find out more about each category and to change the default settings.
Privacy Statement
Required cookies are necessary for basic website functionality. Some examples include: session cookies needed to transmit the website, authentication cookies, and security cookies.
Functional cookies enhance functions, performance, and services on the website. Some examples include: cookies used to analyze site traffic, cookies used for market research, and cookies used to display advertising that is not directed to a particular individual.
Advertising cookies track activity across websites in order to understand a viewer’s interests, and direct them specific marketing. Some examples include: cookies used for remarketing, or interest-based advertising.