• 1Installation
  • 2Preliminary Knowledge
  • 3Create MObjects
  • 4Manipuate MObjects
  • 5Delete MObjects
  • 6Persistence
  • 7Namespace Free
  • 8Functional Support

MObject.apex

  • Docs
  • Tutorials
Getting started with MObject.apex

Manipuate MObjects

MObjects are designed to be easy to use. You can easily access the fields of the MObjects.

Pricebook2 pb = [ ... ];
MObject mo = MObject.create(pb);
// Get value
String name = (String)mo.get('Name');
// Set value
mo.put('Name', 'New ' + name);
// Get nested value with default value
String modifiedBy = (String)mo.get('LastModifiedBy.Name', 'Unknown');
// Update nested value in a list
mo.put('Opportunities.0.Name', 'New op');

MObjects maintain a pure object relation network, and therefore fields like 'Pricebook2Id' are discouraged in MObjects to refer to references, as you can already access it directly by 'Pricebook.Id'.

Calls of put(xxx) will mark the MObject as dirty, and update operation will be carried out for the dirty MObjects during persistence.

Done