how to get the recently added bean id in after save logic hooks?

I would like to retrieve the most recent id of an inserted data inside the after save method of logic hooks. How should I proceed with this? Thank you

  • The id should be a property of the bean. E.g. if your logic hook file looks like this:

    <?php

        if (!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');
      
        class after_save_class
        {
            function after_save_method($bean, $event, $arguments)
            {
                $id = $bean->id;
            }
        }

    ?>

    Then the most recently saved id will be $bean->id as demonstrated above.