[SalesForce] upserting multiple object types in a single DML

I have a case where i need to do an upsert of different sObjects, and I want to do them all at the same time. I know I can do a multiple records of a SINGLE sObject at the same time if I put them into an array and do an upsert(array) . I was thinking In my case, cast the objects ( a master custom object, a detail custom object,and activities, all instantiated in apex) as sObjects and put them into an sObject array and then do an insert on that… but as of now,that's all i've got…

ideas?

Best Answer

To roll back a partially failed transaction, you can use the following code:

System.savePoint sp = Database.setSavePoint();
try {
  // your logic here
} catch(exception e) {
  apexpages.addmessages(e);
  database.rollback(sp);
  return null; // assuming you're returning a value. Just return; otherwise.
}
// return a successful result, page reference, etc.