0

According to the documentation:

An Apex transaction represents a set of operations that are executed as a single unit. All DML operations in a transaction either complete successfully, or if an error occurs in one operation, the entire transaction is rolled back and no data is committed to the database. The boundary of a transaction can be a trigger, a class method, an anonymous block of code, a Visualforce page, or a custom Web service method.

  • What does a boundary for a 'class method' mean here? Is it any set of DMLs within a function?
  • How do I create a transaction with multiple custom objects?
0
  • What does a boundary for a 'class method' mean here? Is it any set of DMLs within a function?

    Yes within any function you defined all the DMLs included in the class Method. If there are any related trigger with sObjects on which you are performing DML then they wil also included in this boundry.

  • How do I create a transaction with multiple custom objects?

    Here is a code sample for you

    public void insertData(){
    
        Warehouse__c acc = new Warehouse__c(Name = 'Test');
        insert acc;
    
        Inventory__c con = new Inventory__c(Warehouse__c = acc.Id);
        insert con;
    }
    

In the above code sample we have single transacion with custom object. The process is same as we do with standard objects.

  • Thanks @Eric for formating don't know why it didn't work for me. – Tushar Sharma Jan 18 '17 at 7:32
  • Thanks for answering. A related question - If I have an inner function with a set of DML statements and I get an exception, will it rollback just the inner function or the outer function as well. – gerad26 Jan 18 '17 at 8:11
  • @gerad26 if you didn't use try catch then both else the current recrd only which cause the exception. – Tushar Sharma Jan 18 '17 at 8:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.