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
mh@reedmh@reed 

Insert error handling

Scenario:  inserting an object into the database that causes an error.

 

I'm confused by the options here.  If I use a try/catch block,  I can gracefully handle and report the error - great.  What happens if I'm doing the following (without the use of a try/catch block):

 

Database.SaveResult[] results = databse.insert(sObject);

 

If the insert fails,  does the code crash or can I then iterate through the SaveResult array,  test for an error and then report it?

 

Should both methods be used at the same time and what happens if they are?

 

kiranmutturukiranmutturu

if the insert fails it will go to the next conditional block like

 

if(pass){

}

else{

    it will come in to this if fails..u can perform the failed logic here....

}

 

 

i didn'get you in this line  "Should both methods be used at the same time and what happens if they are?"

mh@reedmh@reed

Answered this one myself.  You need to use a try/catch block to catch any unexpected error - seems obvious now...

kiranmutturukiranmutturu

ya for sure...