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
Mike @ BlackTabMike @ BlackTab 

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;
    }

}

 

Best Answer chosen by Admin (Salesforce Developers) 
Avidev9Avidev9
Have you checked object level permission and field level permissions ?
"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

Avidev9Avidev9
Have you checked object level permission and field level permissions ?
"with sharing" key word respects sharing rules and gives you the result that are visible to running user, make sure you need that.
This was selected as the best answer
Mike @ BlackTabMike @ BlackTab
I checked the field level security, it's visible and writable for all
users. I also tried the "Without Sharing" keyword and that didn't seem to
work either.
Avidev9Avidev9

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.

 

for(Integer i = 0; i < 4; i++){
            Related_Addresses__c initRelatedAddress = new Related_Addresses__c();
            initRelatedAddress.Related_PDI__c = preDeliveryInspectionId;
            relatedAddresses.add(initRelatedAddress);
        }

 

Mike @ BlackTabMike @ BlackTab
I'm pre-loading a list of 4 records. The apex:pageblocktable adds 4 rows,
but doesn't display any of the apex:input fields in the columns.
Avidev9Avidev9
I guess there is something wrong with FLS
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.
Mike @ BlackTabMike @ BlackTab
That worked! I checked FLS again and that was the issue.

Thanks