function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Praveen BonaluPraveen Bonalu 

Access the Account Teams from the Contact record

I Have tried to Access the Account Team Members from the contact record and i am not able to achieve it.
How would I Query the AccountTeamMembers from the Contact Object

MY VF:
 
<apex:page controller="MyProfilePageController">  
    <apex:form id="theForm"> 
           <apex:pageBlock title="{!$Label.site.my_profile}">
            <apex:pageBlockSection columns="1" title="My Team">
                <apex:pageBlockTable value="{!myTeam}" var="r">
                    <apex:column value="{!r.Account.Name}"/>
                    <apex:column value="{!r.Phone}"/>
                    <apex:column value="{!r.Email}"/>
                </apex:pageBlockTable>
            </apex:pageBlockSection>
           </apex:pageBlock>
     </apex:form>

Controller 
 
public class MyProfilePageController {

    private User user;
    public List<Contact> myTeam { get; set; }

	public User getUser() {
        return user;
    }

    public MyProfilePageController() {
        user = [SELECT id, email, username, usertype,firstname, lastname, phone, title,
                street, city, country, postalcode, state, localesidkey, mobilephone, extension, fax,
                WHERE id = :UserInfo.getUserId()];
       myTeam = [Select Id, Account.Name, FirstName, LastName, Title, Phone, Email from Contact where AccountId=:user.Contact.AccountId  ORDER BY Name ASC];
        
        
    }

    }

 
James LoghryJames Loghry

 I've added an example of how you could fetch the team members from the account id, which you can fetch from the Contact record like so:
[Select AccountId From Contact Where Id=:yourContactId];
 
public Account getAccountWithTeamMembers(Id accountId){
    return 
        [Select 
            Name
            ,(Select 
                  UserId
                  ,User.Name
                  ,User.Email 
              From 
                  AccountTeamMembers) 
         From 
             Account Where Id = :accountId]; 
}

 
Praveen BonaluPraveen Bonalu
I have written the code to access the AccountTeamMember Object for the customer Portal.I have found that customer portal users cannot access the "AccountTeamMember" object in salesforce 

https://developer.salesforce.com/docs/atlas.en-us.api.meta/api/sforce_api_objects_accountteammember.htm
 
James LoghryJames Loghry
Although it's not best practice and somewhat of security risk, per se, you could create a small class that contains just that method, and have the class use the "without sharing" keyword. 
James LoghryJames Loghry
As an example:
 
public without sharing class NaughtyNaughty{
    public static Account getAccountWithTeamMembers(Id accountId){
        return 
            [Select 
            Name
            ,(Select 
                  UserId
                  ,User.Name
                  ,User.Email 
              From 
                  AccountTeamMembers) 
         From 
             Account Where Id = :accountId]; 
    }
}    


//Then call it in your controller:
NaughtyNaught.getAccountWithTeamMembers(myContactsAccountId);

 
Praveen BonaluPraveen Bonalu
Hi james ,

I have called the above mentioned method in my class but  how can i access this method in the order to display in visualforce page .

Thanks
Praveen