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
Matt HamptonMatt Hampton 

Help With PageBlockTable Conditions

Hello:

 

I cannot figure out what to do here. Here is my situation:

 

I have a custom obeject Zip_Code__c that is in a Master-Detail with custom object Sites__c. The relationship name is References__r.

 

Sites__c has five different record types and what I want to do is create related lists for each RecordType individually. I am attempting to do this through Visualforce. Below is my VF page and extension.

 

<apex:page standardcontroller="Zip_Code__c" extensions="RFMDU">
    <apex:pageBlock >
                <apex:pageBlockTable value="{!Zip_Code__c.Releases__r}" var="zip" width="100%" columns="5">
                <apex:column id="c5" headerValue="MDU">
                    <apex:outputField value="{!zip.Name}"/>
                </apex:column>
                    <apex:column id="c4" headerValue="Units">
                        <apex:outputField value="{!zip.Units__c}"/>  
                </apex:column>
                    <apex:column id="c3" headerValue="Account Manager">
                        <apex:outputField value="{!zip.Account_Manager__c}"/>  
                </apex:column>
                    <apex:column id="c2" headerValue="Release Date">
                        <apex:outputField value="{!zip.Released_To_Sales__c}"/>  
                </apex:column>
                    <apex:column id="c1" headerValue="Zip Code">
                        <apex:outputField value="{!zip.Zip_Code__c}"/>   
                </apex:column>
                </apex:pageBlockTable>
    </apex:pageBlock>
</apex:page>

 

public class RFMDU {

    //private final Sites__c sites;
    
    private List<Sites__c> sites = new List<Sites__c>();

    public RFMDU(Apexpages.StandardController controller) {
      String zipCodeId = controller.getId();

 sites = [SELECT ID, RecordTypeID FROM Sites__c 
                  WHERE Zip_Code__c = :zipCodeId
                  AND RecordTypeId='012C0000000GEJzIAO'];
    }

    public List<Sites__c> getsites() {
        return sites;
    }

    public PageReference save() {
        update sites;
        return null;
    }
}

 

What I am trying to acomplish is for this pageblockTable to display only related objects with RecordTypeID=012C0000000GEJzIAO. I am at a loss. Can anyone help me out here? Is my Controller not written correctly? Am I missing something in my VF code?

 

Thanks in advance,

 

Matt

sivaextsivaext

Hi 

 

The page block table is shows only related objects with record type id ='012C0000000GEJzIAO'  because you query in controller getting only this record types.

 

1. you need query all sites records in single query . i.e need to remove below condition

 AND RecordTypeId='012C0000000GEJzIAO'];

you can display all sites records where zip code equals to current zip code.

 

2. if you want different page block tables different record types

  use "rerendered " tag in page block table.

 

Jia HuJia Hu

try this,

 

<apex:page standardcontroller="Zip_Code__c" extensions="RFMDU">
    <apex:pageBlock >
                <apex:pageBlockTable value="{!sites}" var="zip" width="100%" columns="5">
                <apex:column id="c5" headerValue="MDU">
                    <apex:outputField value="{!zip.Name}"/>
                </apex:column>
                    <apex:column id="c4" headerValue="Units">
                        <apex:outputField value="{!zip.Units__c}"/>  
                </apex:column>
                    <apex:column id="c3" headerValue="Account Manager">
                        <apex:outputField value="{!zip.Account_Manager__c}"/>  
                </apex:column>
                    <apex:column id="c2" headerValue="Release Date">
                        <apex:outputField value="{!zip.Released_To_Sales__c}"/>  
                </apex:column>
                    <apex:column id="c1" headerValue="Zip Code">
                        <apex:outputField value="{!zip.Zip_Code__c}"/>   
                </apex:column>
                </apex:pageBlockTable>
    </apex:pageBlock>
</apex:page>

 

public class RFMDU {

    //private final Sites__c sites;
    
    private List<Sites__c> sites = new List<Sites__c>();

    public RFMDU(Apexpages.StandardController controller) {
      String zipCodeId = controller.getId();

 sites = [SELECT ID, RecordTypeID,
                 Name, Units__c,Account_Manager__c, Released_To_Sales__c, Zip_Code__c
                  FROM Sites__c 
                  WHERE Zip_Code__c = :zipCodeId
                  AND RecordTypeId='012xxxxxx']; 
    }

    public List<Sites__c> getsites() {
        return sites;
    }

    public PageReference save() {
        update sites;
        return null;
    }
}

 

Jia HuJia Hu
In you controller, you set the condition for a specific Record Type, but in your VF page, you just list all the child record by default.

Therefore, you should get records of a specific Record Type from your controller.
Matt HamptonMatt Hampton

Maybe I mis-stated my original question. The goal was to ONLY get those records with the record type that is in the controller. I have made the changes suggested in the controller and it is still pulling all record back. I also attempted to use the "rerender" option but that does not appear to be valid in any place in my VF code. 

 

I used render instead and it worked - except for it left blank rows where the condition was not met.

 

Any other suggestions?

Jia HuJia Hu

Have you revised your VF page, like,
apex:pageBlockTable value="{!sites}",.....

You have to show what you queried in the Controller on your page.