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
Greg GellerGreg Geller 

Filter custom setting list based on user.

Hi all,
I have a custom setting list with two custom fields. I entered  9 entries of data.
User-added image
I want to display 9 items for one user and 8 for all of the rest. Is this possible to do with a list?

Thank you,

Greg
 
Greg GellerGreg Geller
I forgot to mention that I created an apex component to display the list as a select field on a visualforce page.
Component
<apex:component controller="ComplianceSeqController">
    <apex:pageBlock>
        <apex:form>
            <apex:actionFunction name="reRenderComplianceSeq" rerender="complianceSeqs">
                <apex:param name="firstParam" assignTo="{!compSeq}" value=""/>
            </apex:actionFunction>
            
            <apex:outputText>Compliance Sequences</apex:outputText><br/>
            <apex:selectList id="compSeq" value="{!compSeq}" onChange="reRenderComplianceSeq" size="1">
                <apex:selectOptions value="{!complianceSeqs}"/>
            </apex:selectList>
        </apex:form>
    </apex:pageBlock>
</apex:component>
Visualforce Page
<apex:page>
    <c:compliancesequencelistcomp />
</apex:page>

Controller class
public with sharing class ComplianceSeqController {
    public String compSeq {get; set;}
        
    public List<SelectOption> getComplianceSeqs() {
        List<SelectOption> options = new List<SelectOption>();
        
        Compliance_Seq_Values__c seqValues = new Compliance_Seq_Values__c();
        if(seqValues.id == null) {
            seqValues = new Compliance_Seq_Values__c();
             System.debug('Values = ' + seqValues);
        }
        
        Map<String, Compliance_Seq_Values__c> allComplianceSeqs; 
        
        allComplianceSeqs = Compliance_Seq_Values__c.getAll();
        for(Compliance_Seq_Values__c seqValue : allComplianceSeqs.values()) {
            options.add( new SelectOption(String.valueOf(seqValue.Compliance_Seq__c), seqValue.Compliance_Description_del__c));
        }

        return options;
    }
}


 
Pradeep Kumar L.GPradeep Kumar L.G
Hey Greg,

Best option is to have extra field on Custom setting and user level. So that you can filter the custom setting matching values.

For ex:
Custom setting value:  
Name:                                    Code
Code of conduct                      0    
COC                                        0
CPNI                                       1

On User leve 
USER 1 :  Custom field= 0
USER 2:   Custom field =1 

P.S: You should have logic to add the value to custom field on user level when new user is created.

Thanks
Pradeep
Sumit Kumar Singh 9Sumit Kumar Singh 9
Hello,
You can modify your controller like this -
public with sharing class ComplianceSeqController {
    public String compSeq {get; set;}
        
    public List<SelectOption> getComplianceSeqs() {
        List<SelectOption> options = new List<SelectOption>();
        
        Compliance_Seq_Values__c seqValues = new Compliance_Seq_Values__c();
        if(seqValues.id == null) {
            seqValues = new Compliance_Seq_Values__c();
             System.debug('Values = ' + seqValues);
        }
        
        Map<String, Compliance_Seq_Values__c> allComplianceSeqs = Compliance_Seq_Values__c.getAll();
	    
		//I am putting condition on email, you can put condition on any other field like name, last name etc.  too.
		
		Boolean isToShowPickVal = (UserInfo.getUserEmail() == 'abx@xyz.com') ? true : false;
        for(Compliance_Seq_Values__c seqValue : allComplianceSeqs.values()) {
			//suppose we don't want to show 'coc' to all users
			if(seqValue == 'COC'){
						if(isToShowPickVal){
								options.add( new SelectOption(String.valueOf(seqValue.Compliance_Seq__c), seqValue.Compliance_Description_del__c));
						}
			} else {
				options.add( new SelectOption(String.valueOf(seqValue.Compliance_Seq__c), seqValue.Compliance_Description_del__c));
			}      
        }
        return options;
    }
}
Hope, it will help you.

Thanks,
Sumit Kumar Singh