BeanFactory

Overview

An overview of the BeanFactory class which is used to retrieve bean objects.

The BeanFactory Class

The BeanFactory class is used for sane bean loading. The class should be used any time you are creating or retrieving bean objects. It will automatically handle any classes required for the bean.

Instantiating a SugarBean Object (newBean)

To instantiate a SugarBean you can use the newBean() method. This method is typically used when creating a new record for a module or to call properties of the bean.
$bean = BeanFactory::newBean($module);

Retrieving a SugarBean Object Record (getBean)

The getBean() method can be used to retrieve a specific record from the database.
$bean = BeanFactory::getBean($module, $record_id);

Retrieving Module Keys (getObjectName)

The getObjectName() method will return the object name / dictionary key for a given module. This is normally the same as the bean name, but may not be for some modules such as Cases which has a key of ‘aCase’ and an name of ‘Case’.
$moduleKey = BeanFactory::getObjectName($moduleName);