You need to sign in to do that
Don't have an account?
Update Picklist Values - Dynamic APEX?
I have 2 fields. One called contact.employee_type__c and a dependent picklist field called contact.employee_name__c. The employee type is contain 2 picklist values "Internal" and "Consultant". The employee name field is also a picklist that contains a list of all employee names which is dependent on what value is selected in the employee type field.
We want to create a trigger so that after a contact record is created with contact.contact_type__c = Internal or consultant, then it would update the picklist values with that record name. Is this a before insert using dynamic apex? any sample code would be helpful
And my reply still holds.
Apex runs after you save the record. Not while you're editing the record.
Visualforce is the technology you use to display and modify user interfaces. So Visualforce is what you'll want to learn about.
But I want my logic to run after I save the record not while I am editing it. Right when a contact record is inserted, I want to update the picklist values of a field on the contact object. In this case, contact.firstname && contact.lastname will be a value in the contact.employee_name__c depending on whether the contact.contact_type__c is an internal or consultant employee. I noticed there is a dynamic apex method called (getPicklistValue ). I'm not sure a VF page is the right way since I am not trying to change anything in the layout using MVC. I am simply trying to update the picklist values for a field in my schema using an after update trigger
The picklist of employee names is important to our business since we use this field to show who had referred the lead. This way, our internal staff or consultants is credited for the line of business. The dependent picklist was created so we can separate the employees by internal staff and consultants so it's easier for the end user to select and update. This may not be a hot idea to you from a technical perspective but it brought and continues to bring business value to our organization.
We have been updating the employee names in the picklist value set when people are terminated or hired. So....we figured we can use force.com custom code logic to udpate the picklists when an employee is created or determined as no longer employed.
You've made your point about using VF instead of APEX ...i just thought dymanic apex would work since we can query sobjects and update the picklists. I will look into if an MVC would work
thank for your help
you can achieve this but you need to change your design.
you will need to replace your depend field Contact.Employee_name__c by a lookup field to User and add a custom field like user.employeetype__c .
Then via Apex and Visualforce you will replace that lookup field by an home made picklist.
Apex will retrieve your employee by type: [select name from User where user.employee_type__c =:contact.Employee_type__c]
and then you can build a picklist in Apex with the selectoption class and display the result in your visualforce page.