May 31, 2011

Picklist Describe Component

I was working over my custom visualforce page where I am displaying some fields including picklist field , text fields etc. Values filled in these fields are used as a search criteria to fetch records from my organization. There were around 30 picklist fields on this page.


Everything was working fine then I suddenly recognize that this search can be used by all users of my application. Then I logged in as user of different profile other than system admin. Pretty amazing for me that most of the picklist and text fields were not visible, then I jumped into the field level security of my object and found that these fields are not visible to this profile. I traversed back to my visualforce page where I saw that I have used input fields to display picklist and text fields. I changed all text inputFields to inputText but it was very difficult to create 30 select list after describing all picklist values from object.


So I have create a component in which we will pass Object API name and Field API name and drop down will be created with all values of that picklist.


Now how to use this component :


1) Get the component downloaded from app exchange : http://bit.ly/liFjUf
2) Install this package to your organization : http://bit.ly/mgPpaq
3) Now create a visualforce page and class code is provided below :


Apex :
public class TestPicklistController
{
    //Property to hold the selected value of component
    public String SelectedVal {get; set;}
    
    public TestPicklistController()
    {
        SelectedVal = '' ;
    }
    
    public void simpleDebug()
    {
        System.debug(':::::::: ' + selectedVal) ;
    }
}
Visualforce :
<apex:page controller="TestPicklistController">

    <apex:form >

        <apex:pageBlock >

            <apex:pageBlockButtons >
                <apex:commandButton value="Check Selected Value" action="{!simpleDebug}" />
            </apex:pageBlockButtons>

            <apex:outputLabel value="Industry"/>
            <arora:PicklistToPicklist value="{!SelectedVal}" objectName="Account" picklistFieldAPI="Industry" useDefaultValue="true" />

        </apex:pageBlock>

    </apex:form>

</apex:page>
Value (Required) : Selected Picklist Value


objectName (Required) : API Name of Object


picklistFieldAPI(Required) : API Name of picklist value


useDefaultValue(Optional) : True (--None-- will be displayed) , False (Only picklist values will be shown)


Feedbacks are always welcomed, also please let me know if there is any problem.


Cheers

2 comments:

  1. very helpful Input specially in case of user accessibility rights limitation.Here I would like to request to make it usable for Multiselect Picklist also.thanks...

    ReplyDelete
  2. Here is the unmanaged package URL : http://bit.ly/mtthkI

    As many have asked for it.

    @Sandeep now you can do changes in component and make it multiselect picklist.

    ReplyDelete