+ Start a Discussion
jaw999jaw999 

Variable does not exist?

public class MyAccountTeamContacts {
 
    public MyAccountTeamContacts(ApexPages.StandardController controller) {
        
    }
    
    User U = CurrentUser();
    
    list <AccountTeamMember> ATMS (){
      return [select  AccountId from AccountTeamMember where Userid = 'u.id'];
        }
    
   public List<Contact> getGSC () {
   return [select name, title, email, Client_Function__c, phone from contact where accountid IN: ATMS ];
    }
  
} // end class MyAccountTeamContacts

 trying to gather a list of Contacts at accounts the running user is on the Account Team for.

Am getting 

Save error: Variable does not exist: ATMS

though i thought i just built ATMS. Can someone assist? thanks.

Best Answer chosen by Admin (Salesforce Developers) 
SamuelDeRyckeSamuelDeRycke

How about

 

public class MyAccountTeamContacts {
    pulblic MyCurrentUser {
        get;
        set;
    } //only if you also plan to use the user elsewhere, else limit to local  variable in your constructor
    public list < AccountTeamMember > ATMS {
        get;
        set;
    }
    public List < Contact > GSC {
        get;
        set;
    }
    public MyAccountTeamContacts(ApexPages.StandardController controller) {
        MyCurrentUser = CurrentUser();
        ATMS = [select AccountId from AccountTeamMember where Userid = : MyCurrentUser.id]; //using ='u.id' would be considered a literal string, and give no results
        GSC = [select name, title, email, Client_Function__c, phone from contact where accountid IN(select AccountId from AccountTeamMember where Userid = : MyCurrentUser.id)];
        // where account id IN ATMS would not work, ATMS is not a list of id's but a list of full objects.
    }
} // end class MyAccountTeamContacts

 

 

 

All Answers

SamuelDeRyckeSamuelDeRycke

May I ask why  would run 2 queries for what you can do in a single query ? (Or does apex get optimised to run that as a single query ?)

jaw999jaw999

Just using the methods I know - not a lot of technique yet!

jaw999jaw999

any suggestions?

SamuelDeRyckeSamuelDeRycke

How about

 

public class MyAccountTeamContacts {
    pulblic MyCurrentUser {
        get;
        set;
    } //only if you also plan to use the user elsewhere, else limit to local  variable in your constructor
    public list < AccountTeamMember > ATMS {
        get;
        set;
    }
    public List < Contact > GSC {
        get;
        set;
    }
    public MyAccountTeamContacts(ApexPages.StandardController controller) {
        MyCurrentUser = CurrentUser();
        ATMS = [select AccountId from AccountTeamMember where Userid = : MyCurrentUser.id]; //using ='u.id' would be considered a literal string, and give no results
        GSC = [select name, title, email, Client_Function__c, phone from contact where accountid IN(select AccountId from AccountTeamMember where Userid = : MyCurrentUser.id)];
        // where account id IN ATMS would not work, ATMS is not a list of id's but a list of full objects.
    }
} // end class MyAccountTeamContacts

 

 

 

This was selected as the best answer
jaw999jaw999

public class MyAccountTeamContacts {
    pulblic MyCurrentUser {

 

etc.

 

 

error: Save error: Invalid type: pulblic

 

so i went with this and it worked:

 

public class fMyAccountTeamContacts {
   
    public list < AccountTeamMember > ATMS {
        get;
        set;
    }
    public List < Contact > GSC {
        get;
        set;
    }
    public fMyAccountTeamContacts(ApexPages.StandardController controller) {
//        MyCurrentUser = CurrentUser();
        ATMS = [select AccountId from AccountTeamMember where Userid = : UserInfo.getUserId()]; //using ='u.id' would be considered a literal string, and give no results
        GSC = [select name, title, email, Client_Function__c, phone from contact where accountid IN(select AccountId from AccountTeamMember where Userid = : UserInfo.getUserId())];
        // where account id IN ATMS would not work, ATMS is not a list of id's but a list of full objects.
    }
}  //