You need to sign in to do that
Don't have an account?
Patrick Arkesteyn 2
DML without commit
Hi,
I'm new to the SF scene, and have an Oracle background.
A reoccuring procedure I'm doing in Oracle is:
Or is there another way, maybe outside Developer Console, to handle this ?
One more question: is there a way to save/open scripts having anonymous Apex ?
Thanks,
Patrick
I'm new to the SF scene, and have an Oracle background.
A reoccuring procedure I'm doing in Oracle is:
- Execute a DML (insert, update, delete) statement
- Check the correctness by executing a query (select) statement
- If OK, I commit. If not, I rollback all DML
Or is there another way, maybe outside Developer Console, to handle this ?
One more question: is there a way to save/open scripts having anonymous Apex ?
Thanks,
Patrick
- In apex everything is runs based on government limits such as one transaction can not have more than 150 DML statements OR 1 DML statement can not update more than 10,000 records, OR one SOQL query can not fetch more than 50,000 records at once etc..
-different development tools in apex has its own limits.
- DML statements are not always commited though. Here is how?
When you write statements such as - In addition, Developer console has a window called anonymous code block (Goto Developer Console - Debug - Open Execute Anonymous WIndow) - in which you can execuate the code above and you will see all the account will created.
- Here is a good source for the Apex Limitations: https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_gov_limits.htm
Hope it helps!
As Govind said, you can put your DML statement in a try/catch block, which will rollback the changes automatically if an exception occurs. If your DML statement doesn't throw an exception, however, you can do something like this:
I don't know if there's a built-in way to save Anonymous Apex scripts, but you could put your script logic in an Apex class and then just execute it from Anonymous Apex, like this:
Apex Class:
Anonymous Apex:
First of all, thanks for your quick reply !
I know about the anonymous code window. The problem is, in that window, apparently I can't:
- Execute DML anonymous.
- Execute select anonymous and check the result of my DML in the grid below.
- Only after checking the result, committing or rolling back the DML.
Because the first step would already commit implicitly. Which is difficult to understand for someone like me who is used to work with relational databases like Oracle or MySql (with autocommit off) where you have to commit explicitly.It seems that this can only get done programatically, as in Charisse's example.
If your question was answered, please select a Best Answer so that this question can be marked as Solved.