Note that emails are saved in a related module, with multiple emails per Contact/Account. You can navigate the relationships and iterate over all the emails, but it is a bit more complex. The email1 field is a shortcut to get the primary email.
I also only needed to reload the custom fields before using it with:
$ bean-> custom_fields-> retrieve ();
It looked like this:
<? php
if (! defined ('sugarEntry') ||! sugarEntry) {
die ('Not A Valid Entry Point');
}
// Class to check Account "email1" field and update Custom Field in Account Type Executive
class EmailAccount {
function updateAccount ($ bean, $ event, $ arguments) {
$email_account = $bean->email1;
$account_type = $bean->account_type;
// Confirm that you are an executive account to shoot the hook
if ($account_type == 'Executive') {
// Reload custom fields
$bean->custom_fields->retrieve ();
// Fill in the Custom field
$bean->custom_field = $email_account;
}
}
}
?>