0

Hi i am new to salesforce. I want to display some records on a pageblocktable, which must be based on the picklist field. e.g. If i select Quarter4 from quarter picklist field pageblocktable must show records for the particular quarter. Anyone know how to do that? I am attaching my VF page and controller code here.

VF page-

<apex:page standardController="contact"  extensions="cntrl_bulk_test"> <!-- controller="cntrl_bulk_test" -->
    <apex:form id="frm">
        <apex:pageBlock id="pgBlkSkilllevel">
            <apex:pageBlockTable value="{!lsttopiclevel1 }" var="a">

                <apex:column headerValue="Skill Group">
                    <apex:outputField value="{!a.Skill_Group__c}"/>
                  <!--  <apex:inputfield value="{!a.Skill_Group__c}"/> -->
                </apex:column>

                <apex:column headerValue="Topic Name">
                    <apex:outputField value="{!a.Topic__r.Name}"/>
                </apex:column>

                <apex:column headerValue="Skill Target">
                    <apex:outputField value="{!a.skill_level_expected__c}"/>
                </apex:column>

                <apex:column headerValue="Skill Level">
                    <apex:inputfield value="{!a.Skill_Level__c}"/>
                </apex:column>

                <apex:column headerValue="Year">
                    <apex:inputfield value="{!a.Year__c}"/>
                </apex:column>  

                <apex:column headerValue="Quarter">
                    <apex:inputfield value="{!a.Quarter__c}"/>
                </apex:column>    

            </apex:pageBlockTable>
        <br/>

        <apex:commandButton value="Save" action="{!saveSkillLevelRating}" /> <!--onclick="window.top.location='/{!Contact.id}'; return false"-->
        </apex:pageBlock>
    </apex:form>
</apex:page>

Controller-

public with sharing class cntrl_bulk_test
{
    Public static Id EmployeeId {get;set;}
    Public  List<Contact_Topic_Scale__c> lsttopiclevel{get;set;}
    list<Contact_Topic_Scale__c> LstSkilllevels = new list<Contact_Topic_Scale__c>();
    public List<Contact_Topic_Scale__c> lsttopiclevel1 {get;set;}
   public ApexPages.StandardController controller {get; set;}    

    public cntrl_bulk_test(ApexPages.StandardController controller)
    {
         this.controller = controller;
         EmployeeId =system.currentpagereference().getparameters().get('id');
         Contact coninfo = [select name from contact where id =: controller.getId()];
         lsttopiclevel1 = new List<Contact_Topic_Scale__c>([SELECT Id, Core_Skill_Set__c,Contact_Skill_Set__c,Delta_Actual_vs_Expected__c,Employee__c,Quarter__c,Skill_Group__c,Skill_Level__c,skill_level_expected__c,Year__c,Topic__r.Name FROM Contact_Topic_Scale__c where Employee__c =: coninfo.name ORDER BY Skill_Group__c ASC ]);
    }

    Public PageReference saveSkillLevelRating()
    {
           //controller.save(); // call save method from standart controller
           //System.debug('*******saveSkillLevelRating0*******');

           //PageReference pageRef = system.currentpagereference();
           PageReference pageRef = ApexPages.currentPage();
           System.debug('********************************************************************************lsttopiclevel=' + lsttopiclevel1 );
           update lsttopiclevel1 ;
           System.debug('********************************************************************************lsttopiclevel=' + lsttopiclevel1 );
           return null;
           //return pageRef ;

    }   
}  
0

Use rendered attribute where required for example: see below

<apex:column headerValue="Skill Group">
    <apex:outputField value="{!a.Skill_Group__c}" rendered="{!lsttopiclevel1.Quarter__c = Quarter4}/>
</apex:column>
  • i want this to be dynamic. I want to select particular quarter via picklist and show the records dynamically – koustubh Oct 15 '15 at 4:44
  • @koustubh It works 'DYNAMICALLY'. Quarter__c value changes as id changes. – Venky Oct 15 '15 at 5:00
  • @venky-Thanks for your help, but you are not getting my question. I will elaborate more,what i want is quarter_c picklist field in a VF page and then user will select its values dynamically like quarter1,quarter2,...And then based on that value, records which have quarter_c value=value of picklist selected by user will be fetched. So if i select quarter4 from picklist then i should get all other records which have quarter_c value as quarter4. Now you get my question? – koustubh Oct 15 '15 at 5:13
  • Sorry, i went completely wrong.It is not possible if you want one of the field in the table to be controlling field. Other way is to create quarter field outside the table and fetch the value into soql query in where condition. – Venky Oct 15 '15 at 5:33
  • Ok,tell me how to do that.Any example for the scenario you mentioned. – koustubh Oct 15 '15 at 5:38
0

I assume it works

  <apex:page standardController="contact"  extensions="cntrl_bulk_test"> <!-- controller="cntrl_bulk_test" -->
<apex:form id="frm">
    <apex:pageBlock id="pgBlkSkilllevel">
        <apex:inputfield value="{!cts.Quarter__c}">
            <apex:actionsupport event="onchange" action="{!quart}" rerender="frm"/>
        </apex:inputfield>
       <apex:pageBlockTable value="{!lsttopiclevel1 }" var="a">

            <apex:column headerValue="Skill Group">
                <apex:outputField value="{!a.Skill_Group__c}"/>
              <!--  <apex:inputfield value="{!a.Skill_Group__c}"/> -->
            </apex:column>

            ..........   

        </apex:pageBlockTable>
    <br/>

    <apex:commandButton value="Save" action="{!saveSkillLevelRating}" /> <!--onclick="window.top.location='/{!Contact.id}'; return false"-->
    </apex:pageBlock>
</apex:form>

In class add below:

public Contact_Topic_Scale__c CTS {get;set;}
public pagereference quart(){
 if(cts.quarter__c!= null || cts.quarter != ''){
  lsttopiclevel1 = new List<Contact_Topic_Scale__c>([SELECT Id, Core_Skill_Set__c,Contact_Skill_Set__c,Delta_Actual_vs_Expected__c,Employee__c,Quarter__c,Skill_Group__c,Skill_Level__c,skill_level_expected__c,Year__c,Topic__r.Name FROM Contact_Topic_Scale__c where Quarter__c =: cts.Quarter__c and Employee__c =: coninfo.name ORDER BY Skill_Group__c ASC ]);
   }
 return null;
 }

Quarter__c =: cts.Quarter__c

  • @venky-Thank you very much venky, i will try this code and let you know whether its working or not. – koustubh Oct 15 '15 at 6:03
  • Hi venky, Vf page is showing error saying Content cannot be displayed: Attempt to de-reference a null object – koustubh Oct 15 '15 at 6:20
  • Hi venky now its not returning anything into pageblocktable and giving error URL No Longer Exists – koustubh Oct 15 '15 at 6:55
  • @koustubh It's working for me, i tried the same code. – Venky Oct 15 '15 at 7:06
  • @venky-Appreciate your help venky,but i am not getting the records, i dont know why this is happening.Any other workarounds? – koustubh Oct 15 '15 at 7:41
0

I hope this will work for any queries you can ask again !!

VF =>>>>

<apex:page standardController="contact"  extensions="cntrl_bulk_test"> <!-- controller="cntrl_bulk_test" -->
<apex:form id="frm">

    <apex:pageBlock id="pgBlkSkilllevel">

        <!-- THIS IS THE PICKLIST -->
        <apex:selectList value="{!selectedType}" size="1" label="Quater Type " onchange="fetchQuater()" rerender="pbt">
            <apex:selectOptions value="{!CategoryOptions}" />
        </apex:selectList>


         <apex:pageBlockTable value="{!lsttopiclevel1 }" var="a" id="pbt">

            <apex:column headerValue="Skill Group">
                <apex:outputField value="{!a.Skill_Group__c}"/>
              <!--  <apex:inputfield value="{!a.Skill_Group__c}"/> -->
            </apex:column>

            <apex:column headerValue="Topic Name">
                <apex:outputField value="{!a.Topic__r.Name}"/>
            </apex:column>

            <apex:column headerValue="Skill Target">
                <apex:outputField value="{!a.skill_level_expected__c}"/>
            </apex:column>

            <apex:column headerValue="Skill Level">
                <apex:inputfield value="{!a.Skill_Level__c}"/>
            </apex:column>

            <apex:column headerValue="Year">
                <apex:inputfield value="{!a.Year__c}"/>
            </apex:column>  

            <apex:column headerValue="Quarter">
                <apex:inputfield value="{!a.Quarter__c}"/>
            </apex:column>    

        </apex:pageBlockTable>
    <br/>

    <apex:commandButton value="Save" action="{!saveSkillLevelRating}" /> <!--onclick="window.top.location='/{!Contact.id}'; return false"-->
    </apex:pageBlock>
</apex:form>

Controller =>>

public with sharing class cntrl_bulk_test
{
Public static Id EmployeeId {get;set;}
Public  List<Contact_Topic_Scale__c> lsttopiclevel{get;set;}
list<Contact_Topic_Scale__c> LstSkilllevels = new  list<Contact_Topic_Scale__c>();
public List<Contact_Topic_Scale__c> lsttopiclevel1 {get;set;}
public ApexPages.StandardController controller {get; set;}    

//TO GET THE VALUE WHICH VALUE IS SELECTED FROM PICKLIST
public string selectedType {get;set;}

public cntrl_bulk_test(ApexPages.StandardController controller)
{
     this.controller = controller;
     EmployeeId =system.currentpagereference().getparameters().get('id');
     Contact coninfo = [select name from contact where id =: controller.getId()];
     lsttopiclevel1 = new List<Contact_Topic_Scale__c>([SELECT Id, Core_Skill_Set__c,Contact_Skill_Set__c,Delta_Actual_vs_Expected__c,Employee__c,Quarter__c,Skill_Group__c,Skill_Level__c,skill_level_expected__c,Year__c,Topic__r.Name FROM Contact_Topic_Scale__c where Employee__c =: coninfo.name ORDER BY Skill_Group__c ASC ]);
}

//THIS WILL FETECH ALL VALUES FROM QUATER IN THE PICKLIST

public List<SelectOption> getCategoryOptions() {
List<SelectOption> options = new List<SelectOption>();      
Schema.DescribeFieldResult fieldResult = Contact_Topic_Scale__c .Quarter__c.getDescribe();
List<Schema.PicklistEntry> ple = fieldResult.getPicklistValues();
options.add(new SelectOption('All','<--Any Type-->'));    
for( Schema.PicklistEntry f : ple)
    {
     options.add(new SelectOption(f.getLabel(), f.getValue()));
    } 
    return options;
}

//THIS FUNCTION CALL WHEN SELECT ANY PICKLIST VALUE AND SHOW RECORDS ACCORDING TO THEM
public PageReference fetchQuater() {
    lsttopiclevel1 = new List<Contact_Topic_Scale__c>();
    if(selectedType == 'All') {
         lsttopiclevel1 = [SELECT Id, Core_Skill_Set__c,Contact_Skill_Set__c,Delta_Actual_vs_Expected__c,Employee__c,Quarter__c,Skill_Group__c,Skill_Level__c,
                      skill_level_expected__c,Year__c,Topic__r.Name 
                      FROM Contact_Topic_Scale__c 
                      WHERE Employee__c =: coninfo.name ORDER BY Skill_Group__c ASC ] ;
    }
    else {
         lsttopiclevel1 = [SELECT Id, Core_Skill_Set__c,Contact_Skill_Set__c,Delta_Actual_vs_Expected__c,Employee__c,Quarter__c,Skill_Group__c,Skill_Level__c,
                      skill_level_expected__c,Year__c,Topic__r.Name 
                      FROM Contact_Topic_Scale__c 
                      WHERE Quarter__c =: selectedType ORDER BY Skill_Group__c ASC ] ;
    }
    return null;
}
Public PageReference saveSkillLevelRating()
{
       //controller.save(); // call save method from standart controller
       //System.debug('*******saveSkillLevelRating0*******');

       //PageReference pageRef = system.currentpagereference();
       PageReference pageRef = ApexPages.currentPage();
       System.debug('********************************************************************************lsttopiclevel=' + lsttopiclevel1 );
       update lsttopiclevel1 ;
       System.debug('********************************************************************************lsttopiclevel=' + lsttopiclevel1 );
       return null;
       //return pageRef ;

}   
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.