This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// New account | |
Account a = new Account(Name = 'New Account'); | |
insert a; | |
// If DML failed, salesforce shows error and rolls-back the new record | |
// New Case linked to account | |
Case c = new Case(subject = 'I need help', accountId = a.id); | |
insert c; | |
// If DML failed, salesforce shows error and rolls-back the new record |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// New account | |
Account a = new Account(Name = 'New Account'); | |
try{ | |
insert a; | |
system.debug('Success'); | |
} catch(dmlexception e){ | |
// If DML failed, ends up here |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Record the place "in time" where we would ultimately like to return the state of the database to upon an error. | |
Savepoint sp = Database.setSavepoint(); // <<<<<<<<<<<< | |
// New account | |
Account a = new Account(Name = 'New Account'); | |
try{ | |
insert a; | |
system.debug('Success'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
trigger CaseTrigger on Case (after insert) { | |
system.debug('***CaseTrigger begin'); | |
// In this example trigger we are simply wanting to flag at the Account level | |
// that the Account has a Case linked to it, which is a lookup field on Case | |
// so we wouldn't be able to do a rollup count. | |
// In reality we would also want to track deletes of Cases but that is skipped | |
// for demonstration purposes. | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
trigger CaseTrigger on Case (after insert) { | |
system.debug('***CaseTrigger begin'); | |
// In this example trigger we are simply wanting to flag at the Account level | |
// that the Account has a Case linked to it, which is a lookup field on Case | |
// so we wouldn't be able to do a rollup count. | |
// In reality we would also want to track deletes of Cases but that is skipped | |
// for demonstration purposes. | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
trigger CaseTrigger on Case (after insert) { | |
system.debug('***CaseTrigger begin'); | |
// In this example trigger we are simply wanting to flag at the Account level | |
// that the Account has a Case linked to it, which is a lookup field on Case | |
// so we wouldn't be able to do a rollup count. | |
// In reality we would also want to track deletes of Cases but that is skipped | |
// for demonstration purposes. | |