I am working on creating my first wrapper class where I will want to allow users to select from a list of sites (custom object Site__c) and it will relate the site to a quote record through an Associated_Location__c object record.
Right now I am stuck on passing over the AccounId. I was hoping that the controller.getRecord().Id would pass the AccountId into the SOQL query but my query is giving me the old 'List has no rows for assignment to SObject'. I think this has to do with my StandardController being Associated_Location__c as it does not have an AccountId. How can I resolve this issue? Thanks in advance!
public class quoteAssociatedSiteExtension {
public List<assLoc> assLocList {get; set;}
public Quote theQuote;
public quoteAssociatedSiteExtension(ApexPages.StandardController controller) {
theQuote = [select Id, AccountId from Quote where Id =:controller.getRecord().Id limit 1];
}
public List<assLoc> getAssLoc() {
if(assLocList == null) {
assLocList = new List<assLoc>();
for(Site__c s: [select Id, Name, Account__r.Id from Site__c where Account__r.Id=:theQuote.AccountId limit 10]) {
assLocList.add(new assLoc(s));
}
}
return assLocList;
}
public PageReference processSelected() {
List<Associated_Location__c> selectedAssociatedLocations = new List<Associated_Location__c>();
for(assLoc aLoc: getAssLoc()) {
if(aLoc.selected == true) {
selectedAssociatedLocations.add(aLoc.ac);
}
}
System.debug('These are the selected Contacts...');
for(Associated_Location__c ac: selectedAssociatedLocations) {
system.debug(ac);
}
assLocList=null;
return null;
}
public class assLoc {
public Associated_Location__c ac {get; set;}
public Site__c st {get; set;}
public Quote qt {get; set;}
public Boolean selected {get; set;}
public assLoc(Associated_Location__c a) {
ac = a;
selected = false;
}
public assLoc(Site__c s) {
st = s;
selected = false;
}
public assLoc(Quote q) {
qt = q;
selected = false;
}
}}
Visualforce Page:
<apex:page standardController="Associated_Location__c" extensions="quoteAssociatedSiteExtension">
<apex:form >
<apex:pageBlock >
<apex:pageBlockButtons >
<apex:commandButton value="Process Selected" action="{!processSelected}" rerender="table"/>
</apex:pageBlockButtons>
<apex:pageBlockTable value="{!AssLoc}" var="a" id="table">
<apex:column >
<apex:inputCheckbox value="{!a.selected}"/>
</apex:column>
<apex:column value="{!a.st.Name}" />
</apex:pageBlockTable>
</apex:pageBlock>
</apex:form>