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
arishi0arishi0 

Visualforce page datalist not returning any values.

Hello,

 

I have a visualforce page that is supposed toreturn a list of contacts using a controller and some queries. This all is supposed to vary according to the product that is being selected in a picklist above. The problem is that the picklist autopopulates with the correct products but when I select one it does not return any contacts where I know that the selected product has been contracted by an account (via custom object: Participation Details) and that the account has a contact. Yet I get nothing.

 

The idea is that the contactList be rerendered to select the apropiarte contacts when a product is selected. I also need to add a button that will export  the contact list to an excel file, this I have not yet figured out how to do.

 

I have pasted the controller code and the VF code to see if anyone can point out my mistake since I go over it once and again and cannot see where I am flawing. I know it is a little challenging to read all this but I need to complete this and ran out of ideas.

 

 

/*--CONTROLLER CODE--*/

public class contact_fromAcc_by_ProdServ { //constructors    public contact_fromAcc_by_ProdServ(ApexPages.StandardSetController standard) {    }    public contact_fromAcc_by_ProdServ() {    }       public String selectedProduct {get;set;}    public List<Account> accs;    public List<Contact> contacts; public List<Id> pdsAccIds; public Products_Services__c currentProduct;

public class contact_fromAcc_by_ProdServ {
  //constructors    
public contact_fromAcc_by_ProdServ(ApexPages.StandardSetController standard) {    }    
public contact_fromAcc_by_ProdServ() {    }   

public String selectedProduct {get;set;}    
public List<Account> accs;    
public List<Contact> contacts;
 public List<Id> pdsAccIds;
 public Products_Services__c currentProduct;


 // Product/Services Page logic <----
       
    public List<SelectOption> PS_Items {
        get {
            List<selectOption> options = new List<selectOption>();
                options.add(new SelectOption('','-- Choose a Product/Service --'));
                for(Products_Services__c p:[SELECT Id, Name,Type__c from Products_Services__c WHERE P_S_Status__c = 'Active' ORDER BY Type__c ASC]){
this.currentProduct = p;
                    options.add(new SelectOption(p.Name,p.Name));
   }
            return options;}
        set;}



     // Contact Page logic <----  
  public List<Contact> ContactList {get{return contacts;}set;}  

  public void updateContactList() {

  try{
   if (selectedProduct != NULL) {
            //Need to get all the PD for the selectedProduct 
            //pds = [Select p.Account__c From Participation_Detail__c p WHERE p.Product_Service__c = :selectedProduct AND p.Status__c = 'Current' ];
            //Iterate over all the pds and add to a temp account list.
            for(Participation_Detail__c pd: [Select p.Account__c From Participation_Detail__c p WHERE p.Product_Service__c = :selectedProduct AND p.Status__c = 'Current' ])
             { pdsAccIds.add(pd.Account__c);

           if(this.pdsAccIds != null){
           //Get Contact info for accounts in acc list. and set contact info to contacts list.
           this.contacts = [Select c.Subscriptions_SynXis_Selected__c, c.Subscriptions_Customer_Selected__c, c.Id, c.Full_Name__c, c.Fax, c.Email, c.Contact_Type__c, c.AccountId From Contact c WHERE c.No_Longer_with_this_Account__c !=True AND c.EmailBouncedDate = null AND c.AccountId IN:pdsAccIds ];
           }
            }
   }catch (Exception e){
   ApexPages.addMessages(e);
  }
  }

 

 

 

<!--VF page code-->

<apex:page standardController="Contact" extensions="contact_fromAcc_by_ProdServ"   recordSetvar="ContactList" sidebar="false">
    <apex:pageBlock >
        <apex:sectionHeader title="List Contacts from Accounts by Product Service" />
         This page will let you select a Product/Service and it will list all the contacts that are related to accounts that contract that Product/Service via Participation Details. First select
         a Product/Service from the picklist below then wait for the contacts to be calculated and displayed onscreen. Once you can see the contacts, you can permorm regular view actions such as sort,
         export excel file, add/remove fields, etc.
    </apex:pageBlock>
    <br/> 
<!-- Page block to list all ProductServices-->
    <apex:pageBlock >
        <Apex:form >
            <apex:pageBlockSection title="     Active Product Services" showHeader="true" collapsible="false">
               <apex:selectList value="{!selectedProduct}" size="1" multiselect="False" id="products" >
                    <apex:selectOptions value="{!PS_Items}" id="psi"/>
                    <apex:actionSupport event="onchange" action="{!updateContactList}" rerender="contactlist" status="Constatus"/>
                </apex:selectList> 
            </apex:pageBlockSection>
                          
            <apex:pageBlockSection title="     Contacts List" showHeader="true" collapsible="false">
                <apex:actionStatus id="Constatus"> Updating Contact List... </apex:actionStatus>
                Size of the Acc list: <apex:variable value="{!testVarINT}" var="c"/> {!c}
                <apex:actionRegion id="contactRegion">                
                    <apex:dataList var="c" value="{!ContactList }" id="contactlist">
                        {!c.Full_Name__c}                  
                    </apex:dataList>
                </apex:actionRegion>
            </apex:pageBlockSection> 

            <apex:panelGrid columns="2"> 
                <apex:commandLink styleClass="btn" action="{!previous}" rerender="Contactlist">Previous</apex:commandlink><apex:commandLink styleClass="btn" action="{!next}" rerender="Contactlist">Next</apex:commandlink> 
            </apex:panelGrid> 
        </apex:form> 
    </apex:pageBlock>
</apex:page>

 

 

 

 

Thank you !!!!!!

Pradeep_NavatarPradeep_Navatar

It seems that the problem is related to the code. Can you put <apex:actionSupport> below the selectlist and selectoption below the actionsupport?

arishi0arishi0

Hello and thank you for your input. I wanted to tell you that I have made the changes you suggested and to no sucess. It still does not show any contacts and I know it should so it is like you say, there certainly is something wrong with the code, I just cannot pinpoint it. below is the snippet of code that hows the changes you suggest...

 

 

<apex:pageBlockSection title="Active Product Services" showHeader="true" collapsible="false">
<apex:selectList value="{!selectedProduct}" size="1" multiselect="False" id="products" >
<apex:actionSupport event="onchange" action="{!updateContactList}" rerender="contactlist" status="Constatus"/>
<apex:selectOptions value="{!PS_Items}" id="psi"/>
</apex:selectList> 
</apex:pageBlockSection>

 

Another thing, when I Select a value in the Products picklist for the first time a new space is added to the end of the page, which is not what I want to happen, but I do not know why, below is a smal screenshot of what Im saying:

 

NOTE THIS WAS ALREADY HAPPENING BEFORE MAKING THE CHANGES YOU SUGGESTED, SO IT IS NOT CAUSED BY THE CHANGE IN THE CODE.

 

This is before selecting the product for the first time. After first time it does not happen since the space is already there.

Thsi is the extra space added after selecting a product service for the first time.

 

This is the results when I select a product from the picklist. PLease note the extra space created right after the picklist.

 

This is theextra space added for some reason after selecting the product.