+ Start a Discussion

Picklist Value while Creating a record



I have a scenraio, can any body please suggest the solution.


I want to display administrator profile users in a picklist, that picklist should be placed on page layout.

While creating a new record i need to choose a user from picklist, that value should be saved in the record.



I am  planning to put picklist on visualforce page, and visualforce page would be added on the page layout.

If i do that how can i get the select value from picklist while saving the record?


I believe trigger doesnot work. How can i do that?  Can any body suggest me,






for this you should override this page by VF page and then you can use apex :Select list for this. there is not other way is remaining for this.


In order to execute this functionality you cannot just add the visualforce page in th epagelayout nad make it done.

You have to override the standard page with your custom visualforce page and save it in you custom save button.


If this post is helpful please throw Kudos.If this post solves your problem kindly mark it as solution.



Yes Saurav we can't override Edit mode standard page. we can only override Detail page. ( keep in mind that you should use standard controller of same object in VF page)

How can i get the value of picklist which in visualforce page while creating the record? I cant user trigger right.

for this you need to apply query on user object where pofile is your expected prfofile and status is active now you can just simply use apex:selectList in order to show pick list/




Thanks for the reply. I have created a VF page with picklist values.But my question is how can i get the select picklist value while saving the record. Because picklist value is there in visualforce page and visualforce page is there on the page layout. I want to get the picklist value while creating the record from the VF page. VF page has a different controller.

If i use trigeer with before insert, i cant get the value of picklist?  Could you clearly explain the solution.


public class AdvisorsController {
//Picklist selected Value
public String selectedValue { get; set; }

//Picklist values
public List<SelectOption> getAdvisors() {
List<SelectOption> options = new List<SelectOption>();
Profile profileID =[Select Id from profile where name = 'Advisor'];
for( User obj:[SELECT CommunityNickname FROM User where profileid = : profileID.Id] )
options.add(new SelectOption(obj.CommunityNickname ,obj.CommunityNickname ));
return options;

//Constructor to initialize picklist value
public AdvisorsController () {
selectedValue = 'advisor1';




VF Page



<apex:page controller="AdvisorsController">
<apex:form >
    <apex:pageBlock mode="edit">
        <apex:pageBlockButtons location="top">
                 <apex:selectList multiselect="false" size="1" value="{!selectedValue}">
                     <apex:selectOptions value="{!Advisors}"/>





For this you need to assign "selectedValue" in your field of object before applying Save method.


How can i assign the selected value to the field of the object.   Selected value is there in the controller of visual force right?


Then what is the event to assign it?  Lets assume if it is before insert trigger, how can i get the selected value of the picklist?


Tell me the scenario how do you get the object of picklist and where do you write the logic of assigning to field?





it will be automatically available in controller when you click on save button ( save button and this pick list should be in same apex:form)


Pick list and Save button are not in the same apex page. Here is the scenario.


-User names populated in Picklist

-Picklist is on Visual force page

-Visual Force page added as a section in page layout of custom object.



Now how can i get the selected value of Picklist which is in controller of visualforce page. Because in the before insert trigger, if i create an object to controller class of VF page,its going to be new object, it does not have what value i selected in the picklist. 



It is not possible because your save button is not on page where you have picklist field. Please override complete page by VF page then you will be able to do it.


Yes. you are right. But i cant override entire pagelayout, because i have almost 10 sections in that page layout, it will take lot of time. Lets try to achieve this in another scenario. 



- Add a new field with the data type formula

- Write a formula to populate users whose profile is 'Advisor' .




Cant we achieve in above scenario.  I tried to write a formula to populate users based profile name='Advisor'

But i could not find profile field in User object while writing the formula.  









Ok then You can do one more thing:-


In inline page you should also provide one more button of save changes along with your custom pick list. so you can save selected value to record but in this approach you need to click on two Save button one is custom button of in line page and other is Standard layout save button.


Inline page means VisualForce page?  In this new approach there is no visualforce.


I thought of putting a formula field or picklist field and write the formula to populate users whose profile is 'Advisor'.


I tried this approach, but it is not working. Is there any better way.