I have an apex code for a visualforce page but I'm having a bit of an issue returning values from the account object which is one of the master objects in my junction object. The code below shows the part of my code where i have identified the issue to be from.
public with sharing class ACScontroller {
public id uuid;
public id acctid;
public list<AccountAssociatedSite__c> relatesites;
public list<String> siteac;
public list<AccountAssociatedSite__c>listOfSiteAccounts;
public ACScontroller()
{
this.uuid = UserInfo.getUserid();
this.acctid = [select accountid from user where id = :uuid][0].accountid;
this.relatesites = [Select RelatedSite__c,RelatedSite__r.Related_Site__c,RelatedAccount__c,RelatedSite__r.Name From AccountAssociatedSite__c a where RelatedAccount__c = :acctid];
this.siteac = new List<String>();
this.listOfSiteAccounts = new list<AccountAssociatedSite__c>();
acssites();
acsites();
System.debug('Printing...');
System.debug(siteac);
System.debug(listOfSiteAccounts);
}
public ApexPages.StandardSetController setAccountSites {
get {
if(setAccountSites == null) {
setAccountSites = new ApexPages.StandardSetController(Database.getQueryLocator(
[Select a.RelatedSite__r.Account_Account_Site__c, a.RelatedSite__r.Related_Site__c, a.RelatedSite__r.Name,
a.RelatedSite__c, a.RelatedAccount__r.Name,
a.RelatedAccount__c, a.Name From AccountAssociatedSite__c a where RelatedAccount__c = :acctid]));
}
return setAccountSites;
}
set;
}
//initialize setAccounts and return records
public List<AccountAssociatedSite__c> getBFSites() {
return (List<AccountAssociatedSite__c>) setAccountSites.getRecords();
}
public void acssites(){
for(AccountAssociatedSite__c res : relatesites){
siteac.add(res.RelatedSite__r.Related_Site__c);
System.debug(siteac);
}
}
public void acsites(){
for(string sitename : siteac){
listOfSiteAccounts = [select RelatedAccount__r.Name,RelatedSite__r.Related_Site__c from AccountAssociatedSite__c where RelatedSite__r.Related_Site__c = :sitename];
System.debug(listOfSiteAccounts);
}
}
public ApexPages.StandardSetController setAllAccountsOfSites {
get {
if(setAllAccountsOfSites == null) {
setAllAccountsOfSites = new ApexPages.StandardSetController(listOfSiteAccounts);
}
return setAllAccountsOfSites;
}
set;
}
//initialize setAllAccountsOfSites and return records
public List<AccountAssociatedSite__c> getAccountsOfSites() {
return (List<AccountAssociatedSite__c>) setAllAccountsOfSites.getRecords();
}
}
The code does not return any errors but I am unable to get any values added to the siteac list of type string - I found this out using the developer console to debug. I'm not sure why. (Related_Site__c
is a URL but for some reason apex returns it as a String, and hence my use of list of type String).
Also AccountAssociatedSite__c
is a junction object with the account object as one of its masters. I just want to return a list of accounts which share a site - so for each site, I return all the accounts that use that site.
Thanks for any suggestions.
List<String>
in your code? I think you've stripped too much out of it in your efforts to make it presentable. At this point, it's not valid apex nor accurate pseudocode. Can you make corrections to the markup so that it accurately represents your Lists and methods?