You need to sign in to do that
Don't have an account?

apex:pageBlockTable's variable doesn't retrieve data
I have a visualforce controller that creates a list of related_addresses__c records, and when I try to access this list the apex:input fields don't populate any data. Any Idea why this would be happening? Could this be a Summer '13 bug?
VF:
<apex:page standardController="Pre_Delivery_Inspection__c" extensions="addRelatedAddressesController" sidebar="true" showHeader="true" showChat="false"> <apex:form id="Related_Address_Form"> <div style="width:600px; margin: 0 auto;"> <apex:sectionHeader title="Add Related Addresses" description="Relate Addresses to a Pre-Delivery Inspection"/> <apex:messages /> <apex:pageblock > <apex:pageBlockButtons > <apex:commandButton value="Save" action="{!save}"/> <apex:commandButton value="Cancel" action="{!Cancel}"/> <apex:commandButton value="Add Row" action="{!addrow}" immediate="false" rerender="table,error"/> <apex:commandButton value="Remove Row" action="{!removeRow}" immediate="false" rerender="table,error"/> </apex:pageBlockButtons> <apex:pageblockTable value="{!relatedAddresses}" var="a" id="table" width="600px"> <apex:column headerValue="Related Addresses" > <apex:selectList value="{!a.Address__c}" multiselect="false" size="1"> <apex:selectOptions value="{!RelatedAddressOptions}"/> </apex:selectList> </apex:column> <apex:column headerValue="Address Type"> <apex:inputField value="{!a.Address_Type__c}" /> </apex:column> </apex:pageblockTable> </apex:pageblock> <!--This is an example, and should be removed --> <apex:selectList multiselect="false" size="1"> <apex:selectOptions value="{!RelatedAddressOptions}"/> </apex:selectList> </div> </apex:form> </apex:page>
Controller:
public with sharing class addRelatedAddressesController { //Class Variables public List<Related_Addresses__c> relatedAddresses {get; set;} private final Pre_Delivery_Inspection__c pdi; public String accountId = ApexPages.currentPage().getParameters().get('acctid'); public String preDeliveryInspectionId = ApexPages.currentPage().getParameters().get('pdiid'); public addRelatedAddressesController(ApexPages.StandardController controller) { this.pdi = (Pre_Delivery_Inspection__c)controller.getRecord(); relatedAddresses = new List<Related_Addresses__c>(); for(Integer i = 0; i < 4; i++){ Related_Addresses__c initRelatedAddress = new Related_Addresses__c(); initRelatedAddress.Related_PDI__c = preDeliveryInspectionId; relatedAddresses.add(initRelatedAddress); } } public List<SelectOption> getRelatedAddressOptions(){ List<SelectOption> addressOptions = new List<SelectOption>(); addressOptions.add(new SelectOption('', '--None--')); //Select Related Address Records if(accountId != null){ List<Address__c> relatedAddressList = [SELECT id, Name FROM Address__c WHERE Account__c = :accountId AND Address_Type__c INCLUDES ('Title To', 'Register To', 'DOT Info')]; for(Address__c address : relatedAddressList){ addressOptions.add(new SelectOption(address.Id, address.Name)); } } System.debug('Address Option Count: ' + addressOptions.Size()); return addressOptions; } public void addRow(){ Related_Addresses__c newRelatedAddress = new Related_Addresses__c(); newRelatedAddress.Related_PDI__c = preDeliveryInspectionId; relatedAddresses.add(newRelatedAddress); } public void removeRow(){ Integer i = relatedAddresses.size(); if(i != 0){ relatedAddresses.remove(i-1); } } public pageReference save(){ //Validate fields before saving Integer j = 0; while(j < relatedAddresses.size()){ if(relatedAddresses.get(j).Address__c == null || relatedAddresses.get(j).Address_Type__c == null){ relatedAddresses.remove(j); }else{ j++; } } insert relatedAddresses; PageReference back = new PageReference('/' + preDeliveryInspectionId); back.setRedirect(true); return back; } public pageReference cancel(){ PageReference back = new PageReference('/' + preDeliveryInspectionId); back.setRedirect(true); return back; } }
"with sharing" key word respects sharing rules and gives you the result that are visible to running user, make sure you need that.
All Answers
"with sharing" key word respects sharing rules and gives you the result that are visible to running user, make sure you need that.
users. I also tried the "Without Sharing" keyword and that didn't seem to
work either.
What do you mean by not popuplating data ?
I had a look on the code and seems like you are just adding the initialized object to the list.
but doesn't display any of the apex:input fields in the columns.
Try doing this, Try replacing the inputfield with inputtext if it displays that means you are missing some security settings in user profile FLS or Object level security. Most probably FLS.
Thanks