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
AwaraMohanAwaraMohan 

How do i prevent a record from insert without raising exception or addError

How do i prevent a record from insert without raising exception or addError

phiberoptikphiberoptik

You might want to repost this in the correct forum. This forum is for questions regarding formulas and validation rules. Your question appears to pertain more to development/code.

Madhan Raja MMadhan Raja M

Hi Mohan,

 

You need to make use of Exception Handling in your code.

A great resource for this is :  http://wiki.developerforce.com/page/An_Introduction_to_Exception_Handling

 

If this do not answer your question then post your queries in Apex Code Development discussion.

 

Madhan Raja M

Shivanath DevnarayananShivanath Devnarayanan

Well this does belong to the Apex Code development;

 

but I hope i can help you out or point you in the right direction. Assuming you use exception handling and if error occurs you  would want to roll back the insert

 

on your trigger which delegates to a class add a similar code

 

try
{
 // Any DML performed after this savepoint will be undone should a rollback occur
   Savepoint sp = Database.setSavepoint();

// do some logic 
//Insert your record

}
catch(exception ex)
{
 // Rollback the database to the state held at the time of defining the savepoint

        Database.rollback(sp);

}

 

This is just pseudo code; I'd be glad to help you out if you need more help; I'd also urge you to take a look at this post as it explains this concept in a much better perspective.

 

/* If this solves your problem do mark it as solved so others may benefit */