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
kuldeep paliwalkuldeep paliwal 

i want to show particular records on pageblock,How its done

  <apex:pageblock >
            <apex:pageblockTable value="{!busterSetting}" var="c">
                <apex:column value="{!c.Name}"/>
                <apex:column value="{!c.Object_Name__c}"/>
                <apex:column value="{!c.Field_List__c}"/>       
                <apex:column value="{!c.Layout_Name__c}"/>
            </apex:pageblockTable>

This is my vf shows hear when i open this page its call the custom settings and set all fields but i want to show records which have only particular Layout_Name__c like(which records have Layout_Name__c = search) only show other can not show on my page..
Thanx
Best Answer chosen by kuldeep paliwal
LBKLBK
Hey Kuldeep,

You need to filter out your Custom settings in your APEX Controller and use it in VF Page.

You need add the following code in your Controller, to populate busterSetting list.
 
List<YOUR_CUSTOM_SETTING__c> busterSetting = new List<YOUR_CUSTOM_SETTING__c>();
for(YOUR_CUSTOM_SETTING__c cs:YOUR_CUSTOM_SETTING__c.getall().values()){
  if(cs.Layout_Name__c == 'search'){
    busterSetting.add(cs);
  }
}
Let me know if this helps.
 

All Answers

LBKLBK
Hey Kuldeep,

You need to filter out your Custom settings in your APEX Controller and use it in VF Page.

You need add the following code in your Controller, to populate busterSetting list.
 
List<YOUR_CUSTOM_SETTING__c> busterSetting = new List<YOUR_CUSTOM_SETTING__c>();
for(YOUR_CUSTOM_SETTING__c cs:YOUR_CUSTOM_SETTING__c.getall().values()){
  if(cs.Layout_Name__c == 'search'){
    busterSetting.add(cs);
  }
}
Let me know if this helps.
 
This was selected as the best answer
kuldeep paliwalkuldeep paliwal
List<duplicatebuster__BusterSetting__c> busterSetting = new List<duplicatebuster__BusterSetting__c>();
Constructor:----
for(duplicatebuster__BusterSetting__c cs:duplicatebuster__BusterSetting__c.getall().values()){
                      if(cs.Layout_Name__c == 'FindDuplicateSearchFields'){
                        busterSetting.add(cs);
                        system.debug('--busterSetting--' +busterSetting);
                      }
                }  
i put this on constructor because on page load i want to show this..
on debug its show list but on page it not why..
Thanx..
LBKLBK
Declare busterSetting as a property in the class.

Like this...
 
List<duplicatebuster__BusterSetting__c> busterSetting {get; set;}

 
kuldeep paliwalkuldeep paliwal
yes i initalize this public List<duplicatebuster__BusterSetting__c> busterSetting {get;set;}  
but now its show null pointer exeception
LBKLBK
Can you post your Controller code? Let me take a look at it.
kuldeep paliwalkuldeep paliwal
public class FindDuplicateFieldSetController{
        
        duplicatebuster__Buster_Job__c BusterJobs{ get; set; }
        public Map <String, Schema.SObjectType> schemaMap = Schema.getGlobalDescribe();
        public String selectedObject {get; set;}
        public SelectOption[] selectedFields { get; set; }
        public  List<SelectOption> objNames {get; set; }
        public SelectOption[] allFields { get; set; }
        public String message { get; set; }
        public List<duplicatebuster__BusterSetting__c> busterSetting {get;set;}
        public String saveJobName{get; set;}
        Public Integer noOfRecords{get; set;}
        Public Integer size{get;set;}
        public Boolean displayPopup {get;set;}
       
        Public FindDuplicateFieldSetController(){   
                selectedObject = 'Account';
                selectedFields = new List<SelectOption>();
                getObjectName();

              //  Map<String,duplicatebuster__BusterSetting__c> allbusterSetting = duplicatebuster__BusterSetting__c.getAll();
              // busterSetting = allbusterSetting.values();
              
                List<duplicatebuster__BusterSetting__c> busterSetting = new List<duplicatebuster__BusterSetting__c>();
                for(duplicatebuster__BusterSetting__c cs:duplicatebuster__BusterSetting__c.getall().values()){
                      if(cs.Layout_Name__c == 'FindDuplicateSearchFields'){
                        busterSetting.add(cs);
                        system.debug('--busterSetting--' +busterSetting);
                      }
                }  
         }

        public pageReference getObjectName(){
            system.debug('--selectedObject1 --' +selectedObject );
                objNames = new List<SelectOption>();
                
                    for (Schema.SObjectType obj : schemaMap.values()){
                            Schema.DescribeSObjectResult describeSobject = obj.getDescribe();
                            String Name = describeSobject.getName();
                            String Label = describeSobject.getLabel();
                            
                        if(Name == 'Account' || Name == 'Contact' || Name == 'Lead' || Name == 'Opportunity' || Name == 'Case' || Name == 'KnowledgeArticle' || describeSobject.isCustom()==true){
                            SelectOption so = new SelectOption( Name , Label );
                            objNames.add(so);
                            objNames.sort();
                            system.debug('--objNames--' +objNames);
                            getObjectFields();
                        }
                }
                return null;
        }
    
        public pageReference getObjectFields(){
            System.debug('selectedObject== ' + selectedObject );
                Map<String, Schema.SObjectType> schemaMap = Schema.getGlobalDescribe();
                System.debug('schemaMap == ' + schemaMap);
                Schema.SObjectType ObjectSchema = schemaMap.get(selectedObject);
                Map<String, Schema.SObjectField> fieldMap = ObjectSchema.getDescribe().fields.getMap();
                allFields = new List<SelectOption>();
                
                for (String fieldName: fieldMap.keySet()) {  
                        allFields.add(new SelectOption(fieldMap.get(fieldName).getDescribe().getName(),fieldMap.get(fieldName).getDescribe().getName()));
                        allFields.sort();
                }
                return null;
        }
        
        public pageReference save(){
            duplicatebuster__BusterSetting__c bS = new duplicatebuster__BusterSetting__c();
            String fieldList = '';
            
                if(selectedFields!=null){
                    for( SelectOption so: selectedFields){
                        fieldList = fieldList  + so.getValue() +',';
                    }
                    fieldList = fieldList.removeEnd(',');
                }else{
                         ApexPages.addmessage(new ApexPages.message(ApexPages.severity.WARNING,'Please enter ObjectField'));
                    return null;
                    }
                    System.debug('fieldList==' + fieldList +', selectedFields=='+ selectedFields);
                    
                    if(fieldList!=''){
                        bS.duplicatebuster__Field_List__c=  fieldList;
                    }
                    bS.duplicatebuster__Object_Name__c=  selectedObject;
                    bS.duplicatebuster__Layout_Name__c = 'FindDuplicateSearchFields';
                    bs.Name = saveJobName;
                    insert bS;
                    
                    Pagereference page = new Pagereference('/apex/busterSettings');
                    page.setRedirect(true);
                    return page ;
        }
        
        public pageReference saveAndNew(){
            save();
            displayPopup = true;
            Pagereference page1 = new Pagereference('/apex/FindDuplicateFieldSet');
            page1.setRedirect(true);
            return page1;
            
        }
        
        public pageReference cancel(){
            displayPopup = false;
            PageReference page2 = new PageReference('/apex/busterSettings');
            page2.setRedirect(true);
            return page2 ;
        }
        
        public void showPopup()
        {
            displayPopup = true;
            System.debug('displayPopup=' + displayPopup );
            
        }
        public void closePopup()
        {
             displayPopup = false;
        }
        
        public ApexPages.StandardSetController setCon {
            get{
                if(setCon == null){
                    size = 10;
                    string queryString = 'Select Name, Object_Name__c, Field_List__c,Layout_Name__c  from duplicatebuster__BusterSetting__c';
                    System.debug('queryString =' + queryString );
                    setCon = new ApexPages.StandardSetController(Database.getQueryLocator(queryString));
                    setCon.setPageSize(size);
                    noOfRecords = setCon.getResultSize();
                }
                return setCon;
            }set;
        }
     
        Public List<duplicatebuster__BusterSetting__c> getBusterSettings(){
            List<duplicatebuster__BusterSetting__c> busterList = new List<duplicatebuster__BusterSetting__c>();
            for(duplicatebuster__BusterSetting__c b : (List<duplicatebuster__BusterSetting__c>)setCon.getRecords())
                busterList.add(b);
            return busterList;
        }
         
        public pageReference refresh() {
            setCon = null;
            getBusterSettings();
            setCon.setPageNumber(1);
            return null;
        }
         
        public Boolean hasNext {
            get {
                return setCon.getHasNext();
            }
            set;
        }
        public Boolean hasPrevious {
            get {
                return setCon.getHasPrevious();
            }
            set;
        }
      
        public Integer pageNumber {
            get {
                return setCon.getPageNumber();
            }
            set;
        }
      
        public void first() {
            setCon.first();
        }
      
        public void last() {
            setCon.last();
        }
      
        public void previous() {
            setCon.previous();
        }
      
        public void next() {
            setCon.next();
        }
}


Now its show on the debug not in page..
Thanx
LBKLBK
Since you have declared busterSetting as a public property, you need to comment the following code in your constructor.
 
List<duplicatebuster__BusterSetting__c> busterSetting = new List<duplicatebuster__BusterSetting__c>();

 
kuldeep paliwalkuldeep paliwal
than it show
NullPointerException: Attempt to de-reference a null object
Class.duplicatebuster.FindDuplicateFieldSetController.<init>: line 24, column 1
LBKLBK
My bad. You should not declare the property again in the constructor, however, you need to initialize it.

Replace the above line of code in the constructor with this.
 
busterSetting = new List<duplicatebuster__BusterSetting__c>();

 
kuldeep paliwalkuldeep paliwal
you are g8 thanx LBK..problem solved