The Governor Limit and Savepoint (Salesforce Apex)
Savepoint you set counts against the governor limit for DML statements and rows.
Also, rollback is also the same.
Rows are the number of records. Savepoints and rollbacks were also counted in records.
//
// Execute Anonymous 1
// Insert 2 times, SavePoint, Rollback total 4 times.
// Result, one record of X company is inserted.
//
Account a1 = new Account(Name = 'X Company ');
insert a1;
System.SavePoint sp = Database.setSavePoint();
Account a2 = new Account(Name = 'Y Company');
insert a2;
Database.rollback(sp);
// Debug log
Number of SOQL queries: 0 out of 100
Number of query rows: 0 out of 50000
Number of SOSL queries: 0 out of 20
Number of DML statements: 4 out of 150 <--- counts
Number of DML rows: 4 out of 10000 <--- same counts because inserted every record
Maximum CPU time: 0 out of 10000
Maximum heap size: 0 out of 6000000
Number of callouts: 0 out of 100
Number of Email Invocations: 0 out of 10
Number of future calls: 0 out of 50
Number of queueable jobs added to the queue: 0 out of 50
Number of Mobile Apex push calls: 0 out of 10
//
// Execute Anonymous 2
// Insert 2 times, SavePoint, Rollback total 4 times 6 records.
//
// Differences between statements and rows
// Define the list
// Create account sObjects
// Add accounts to the list
// Bulk insert the list
//
List<Account> acctList = new List<Account>();
Account a1 = new Account(Name='Account1');
Account a2 = new Account(Name='Account2');
acctList.add(a1);
acctList.add(a2);
insert acctList;
System.SavePoint sp = Database.setSavePoint();
List<Account> acctList2 = new List<Account>();
Account a3 = new Account(Name='Account3');
Account a4 = new Account(Name='Account4');
acctList2.add(a3);
acctList2.add(a4);
insert acctList2;
Database.rollback(sp);
// Debug log
Number of SOQL queries: 0 out of 100
Number of query rows: 0 out of 50000
Number of SOSL queries: 0 out of 20
Number of DML statements: 4 out of 150 <--- 4 counts
Number of DML rows: 6 out of 10000 <---- 6 counts as inserted 2 records in 1 list
Maximum CPU time: 0 out of 10000
Maximum heap size: 0 out of 6000000
Number of callouts: 0 out of 100
Number of Email Invocations: 0 out of 10
Number of future calls: 0 out of 50
Number of queueable jobs added to the queue: 0 out of 50
Number of Mobile Apex push calls: 0 out of 10
Transaction Control | Apex Developer Guide | Salesforce Developers https://developer.salesforce.com/docs/atlas.en-us.210.0.apexcode.meta/apexcode/langCon_apex_transaction_control.htm
Each savepoint you set counts against the governor limit for DML statements.
Each rollback counts against the governor limit for DML statements. You will receive a runtime error if you try to rollback the database additional times.
セーブポイントは、DML ステートメントのガバナ制限にカウントされ、DML Rowsも同じ数だけカウントされます。ロールバック実行時も同様に消費されました。
Execute Anonymous 1のApexコードはX社が挿入された後のセーブポイントにロールバックされ、Y社の挿入は取り消しされますので、X社1レコードだけが挿入されます。
Execute Anonymous 2のApexコードは1配列で2レコード挿入してますので、DMLステートメントは4回、Rowsは4レコードとセーブポイント、ロールバックもレコード数になり、合計6回となりました。
Also, rollback is also the same.
Rows are the number of records. Savepoints and rollbacks were also counted in records.
//
// Execute Anonymous 1
// Insert 2 times, SavePoint, Rollback total 4 times.
// Result, one record of X company is inserted.
//
Account a1 = new Account(Name = 'X Company ');
insert a1;
System.SavePoint sp = Database.setSavePoint();
Account a2 = new Account(Name = 'Y Company');
insert a2;
Database.rollback(sp);
// Debug log
Number of SOQL queries: 0 out of 100
Number of query rows: 0 out of 50000
Number of SOSL queries: 0 out of 20
Number of DML statements: 4 out of 150 <--- counts
Number of DML rows: 4 out of 10000 <--- same counts because inserted every record
Maximum CPU time: 0 out of 10000
Maximum heap size: 0 out of 6000000
Number of callouts: 0 out of 100
Number of Email Invocations: 0 out of 10
Number of future calls: 0 out of 50
Number of queueable jobs added to the queue: 0 out of 50
Number of Mobile Apex push calls: 0 out of 10
//
// Execute Anonymous 2
// Insert 2 times, SavePoint, Rollback total 4 times 6 records.
//
// Differences between statements and rows
// Define the list
// Create account sObjects
// Add accounts to the list
// Bulk insert the list
//
List<Account> acctList = new List<Account>();
Account a1 = new Account(Name='Account1');
Account a2 = new Account(Name='Account2');
acctList.add(a1);
acctList.add(a2);
insert acctList;
System.SavePoint sp = Database.setSavePoint();
List<Account> acctList2 = new List<Account>();
Account a3 = new Account(Name='Account3');
Account a4 = new Account(Name='Account4');
acctList2.add(a3);
acctList2.add(a4);
insert acctList2;
Database.rollback(sp);
// Debug log
Number of SOQL queries: 0 out of 100
Number of query rows: 0 out of 50000
Number of SOSL queries: 0 out of 20
Number of DML statements: 4 out of 150 <--- 4 counts
Number of DML rows: 6 out of 10000 <---- 6 counts as inserted 2 records in 1 list
Maximum CPU time: 0 out of 10000
Maximum heap size: 0 out of 6000000
Number of callouts: 0 out of 100
Number of Email Invocations: 0 out of 10
Number of future calls: 0 out of 50
Number of queueable jobs added to the queue: 0 out of 50
Number of Mobile Apex push calls: 0 out of 10
Transaction Control | Apex Developer Guide | Salesforce Developers https://developer.salesforce.com/docs/atlas.en-us.210.0.apexcode.meta/apexcode/langCon_apex_transaction_control.htm
セーブポイントは、DML ステートメントのガバナ制限にカウントされ、DML Rowsも同じ数だけカウントされます。ロールバック実行時も同様に消費されました。
Execute Anonymous 1のApexコードはX社が挿入された後のセーブポイントにロールバックされ、Y社の挿入は取り消しされますので、X社1レコードだけが挿入されます。
Execute Anonymous 2のApexコードは1配列で2レコード挿入してますので、DMLステートメントは4回、Rowsは4レコードとセーブポイント、ロールバックもレコード数になり、合計6回となりました。
コメント
コメントを投稿