Custom class not working on saving bean and only working on mass update

HIi, I want to override the save method of ‘Lead’. For this as per the documentation i have registered the custom class in ’

custom/extension/application/Ext/include/customLead.php’

the code is

$objectList['Leads'] = 'Lead';

// $beanList maps the Bean/Module name to the Class name
$beanList['Leads'] = 'CustomLead';

// $beanFiles maps the Class name to the PHP Class file
$beanFiles['CustomLead'] = 'custom/modules/Leads/CustomLead.php';

and in the ‘custom/modules/leads/CustomClass.php’

i have this code

require_once 'modules/Leads/Lead.php';


class CustomLead extends Lead
{
    /**
     * Saves the record
     * - You can use this method to implement before save or after save logic
     *
     * @param bool $check_notify
     * @return string
     */
    function save($check_notify = FALSE)
    {
       $GLOBALS['log']->fatal('---------Here----------');


        $value = parent::save($check_notify);
        return $value;
    }
}

When i run the mass update it runs this code perfectly but when i save a single record there is error of not registering the custom class.

Haven’t tried this but may be this will help you

Is this still in development?

I believe it is included from 7.11.14.
You may have a look here.

Shouldn’t you just be overriding the Controller’s Save action?

No need to mess with Beanfiles array.

Thanks for the reply actually it was method written on the official sugarcrm website. Anyhow making a controller and overriding the save function will it override all the functionality available in Lead.PHP ??

Can you please point me to that documentation?

I don’t think it’s needed for this case. Overriding one of the Controller’s actions is pretty standard, it’s upgrade-safe, it’s object-oriented, it’s elegant.

You only need to define what you want to change, and you can call the code from parent easily.

@pgr sorry for late reply. Here is the link which i am following

override sugar bean

Secondly if i override can i change the notify bit as my main concern is changing the
check_notify on some logic. how to achieve this using the overriding the controller.

i don’t think that is the correct technique to apply here.

The link I gave above has a specific section for “pre-existing modules”, try that one.

The only doubt I have about recommending this is that the leads module uses the legacy controller system, where a file called Leads/Save.php executes the Save action. The newer controller system would use a action_save method in the controller class.

I am sure you can customize the newer controller system, I am not so sure what happens with the old one… the only way to find out is to try.