You need to sign in to do that
Don't have an account?
NIKHIL_SFDC
Add new Picklist value with trigger.
Hi,
I want to write some trigger on Product2 object so that when any new product record is created it can add new picklist value on Picklist__c (Picklist field) under CustomObject__c object.
Any help would be appreciated.
Thanks,
Nikhil
You want to add a new value to the Picklist? If so, that is not possible as far as I know.
I believe that If at all this is possible it is possible via only Meta Data API but not Apex code.
Moreover, If there is no definite/predictable set of values in your picklist then your Data Modeling is wrong. If that is the case you should have made that as custom object itself.
And If there is predictable Super set of Values but you want to show different sub sets of values in different scenarios you should use RecordTypes.
Hi Nikhil,
You can do this using MetaDataAPI. In MetadataAPI you can add picklist Value.
In following code we add two and three as a picklist value Picklist__c field on Lead.
Use following code in your APEX class:
If this is your solution then please mark as a solution and it helps other for similar issues.
Hi singh,
Can you please explain me how did you update the picklist values by using above class which you have mentioned
when I was trying to save your class in my instance I got below error.
Error: Compile Error: Invalid type: MetadataService.MetadataPort at line 5 column 13
so can you please explain or list out steps to add the picklist values using apex class.
how the class should be ?
how can we invoke your code is by using trigger or VF page
Hi ,
have you able to added new picklist values , did you get any soulution.
If you have any solution can you please post me.
I need to also add new picklist values, is it possible by using metadat or apex.
If it is can you please explainme how to do that.
Hi,
Using metadata api how to create Multiselect picklist From visualforce page in salesforce?
I am getting an error like MetaDataService.MetadataPort invalid.Please provide me solution. Thanks in advance.