Get the Primary Email Address for a record using the bean

sugarcrmdevelopers —  December 26, 2012 — 2 Comments

I always like to see people leveraging articles such as this one to better explore all the SugarBean model layer provides the developer, in the process helping them avoid complex SQL queries and tedious parsing of the results from them. Here’s the question from the forums on this…

I am looking in Sugarce v 6.5.4 where I have the User Id in user’s table . I need to fetch the primary email id of that user using that ID . How It can done ?
I know there is a relation b/w email_addressses and email_addr_bean_rel . I don’t know how they relate each other ? please advise me with a solution

Community member agcopley jumped in here with a nice solution that leverages the SugarBean framework to a ‘T’…

The key is the call to SugarEmailAddress::getPrimaryAddress(), which automatically will only return the address marked as the primary one. If none are marked primary, it assumes the first one entered for that user is the primary one.

Thanks again agcopley for the tip!

2 responses to Get the Primary Email Address for a record using the bean

  1. 

    i tried a same thing for leads its not fetching for leads module is this method only applicable for user modules

    $leads=BeanFactory::getBean(‘Leads’,$focus->id);
    echo $primary_email=$user->emailAddress->getPrimaryAddress($leads);

    ?? ami doing some thing wrong ??

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s