You need to sign in to do that
Don't have an account?

Show picklist value on visualforce page for selected users
Hey guys,
We have an apex class and VF page called Register. On this page the user can select from 4 different values on a picklist field called Type.
Is it possible to show all fours selections to all users that have Agent (checkbox) as TRUE on their user profile?
So what I would need is any currently logged in user with Agent as TRUE will see Options 1,2,3,4 and any user with Agent as FALSE will see options 1,2,3.
Can this be done?
Please find below code, that will help you in fulfilling your requirement:
Add valued based on Profile and Agent check box:
Hope this will helps you.
Thanks,
Gaurav
Email: gauravgarg.nmims@gmail.com
Skype: gaurav62990
Refer this code :
VF
<apex:page controller="selectOptionBasedonUser">
<apex:form >
<apex:pageBlock >
<apex:outputLabel > <b> Testing : </b> </apex:outputLabel>
<apex:selectList size="1" value="{!selectedTest}">
<apex:selectOptions value="{!TestLst }"/>
</apex:selectList> <br/>
</apex:pageBlock >
</apex:form>
</apex:page>
Class
public class selectOptionBasedonUser {
public boolean istrue;
public List<SelectOption> TestLst {get;set;}
public String selectedTest{get;set;}
public selectOptionBasedonUser (){
for(User iUs : [Select id, name, Agent__c FROM USER WHERE id =: userinfo.getuserid()]){
istrue = iUs.Agent__c;
}
TestLst = new List<SelectOption>();
TestLst.add(new SelectOption('','--None--'));
if(istrue){
TestLst.add(new SelectOption('Test1','Test1',false));
TestLst.add(new SelectOption('Test2','Test2',false));
}
TestLst.add(new SelectOption('Test3','Test3',istrue));
}
}
Regards,
Saravana
You can go through with the following approach,
Create two fields in User object:
1.Agent(Checkbox).
2.Type(Picklist) -put values example-(1,2,3,4)
Now to do the following configuration.
1.Make agent (checkbox) as controlling field
2.Make Type(Picklist) as dependent Field.
Go to fields,click on Field Dependency button,Create a new Dependency,
a.Based on checked value select picklist values.
b.Based on unchecked value select picklist values.
Configuration part is over.
Now execute the following code:
public User usr {get;set;}
User usr=[Select id, name, Agent__c,Type FROM USER WHERE id =: userinfo.getuserid() LIMIT 1];
and display the above info in VF page.
If you have any concern please let me know.
Cheers,
Dhriti