Legacy Approach
Previously, I used to use Apex Metadata Service (https://andyinthecloud.com/2013/10/27/introduction-to-calling-the-metadata-api-from-apex/); but it requires to import all code for even a small requirement. After, release of Tooling API, I find it lifesaver for such implementation.
Below given approach is with help of Tooling api.
Here is one Salesforce stackexchange question: https://salesforce.stackexchange.com/questions/162390/how-to-update-picklist-values-along-with-record-types-using-metadataservice
New Approach
- This protoype is achieved using tooling api and workbench
- Need to refine – remove unwanted metadata in request. If you want to remove then its ok as well.
- If you just want to update/create picklist field then you will have to just make first HTTP request given below.
- First http call to add/remove/update picklist value.
- Second http call to add new value in record type.
First HTTP Call to Update Picklist Field
PATCH
/services/data/v41.0/tooling/sobjects/CustomField/00N540000071QJG
Here is JSON Body that has to be sent as request body in this callout: https://github.com/ayub-ansari/Create-Picklist-Field-Using-Apex/blob/master/FirstHTTPRequestToUpdatePicklistField
Note:
- Replace Custom field Id with your custom field in above given endpoint.
- Please copy the request body carefully and replace the picklist field metadata. In the given example, we are updating a picklist field “Competitor__c” on Object “Opportunity”. You will have to replace all values, labels and api names.
- Optionally, there is a trick to get picklist field metadata as well. You can get that using workbench –> Rest Explorer and hit
/services/data/v48.0/tooling/sobjects/CustomField/00N9000000DHfrM where ‘00N9000000DHfrM
is existing field with same data type. this call will return json response where you can extract metadata and manipulate as per your requirement. - An important note that, if you are just updating picklist value and there is no controlling field then you may face an error – “Cannot deserialize instance of complexvalue from VALUE_NULL value null or request may be missing a required field”. This is coming because attribute “valueSettings” is set to null but actually it should be []. So replace null with []. You will be able to save it.
2nd HTTP Call to Update Record Type to Include New Picklist Values
PATCH
/services/data/v41.0/tooling/sobjects/RecordType/012f20000009x5X
Please find here example of metadata JSON Request Body: https://github.com/ayub-ansari/Create-Picklist-Field-Using-Apex/blob/master/SecondHTTPRequestToUpdateRecordTypes
Note:
- Replace the record type id with your id in given endpoint.
- Please copy the request body carefully and replace the picklist field metadata. In the given example and replace the values with your metadata.
- Optionally, there is a trick to get picklist field metadata as well. You can get that using workbench –> Rest Explorer and hit
/services/data/v48.0/tooling/sobjects/RecordType/012f20000009x5X
is existing record type. This call will return JSON response where you can extract metadata and manipulate as per your requirement.
Hi Ayub,
Picklist Value creation works fine. But when using get method to retrieve metadata values for a particular record type, it is now showing picklist values. It just shows an empty array.
I used workbench for executing this Rest API.
Please let me know how to get picklist values assigned to a record type using tooling api.
Thanks,
Ajay
I have the same issue. I was able to figure out how to update the global value set using the tooling API. However, it does not apply the new value to each recordtypes.
The UI-APIs is able to pull back the enabled picklists, but it does not allow me to update. Any insights?
For those of us that aren’t coders, can we use this approach but in Salesforce Flows to add a new Picklist Value to a Master List and also to specific Record Types?
how does cbd oil help with insomnia and alertness
amoxicillin 500mg capsules buy amoxil online uk amoxicillin 10 days or 7 what bacteria does amoxicillin kill
500mg amoxicillin amoxicillin 500 mg without a prescription where can i get amoxicillin what is the antibiotic amoxicillin used for
lasix vs bumex lasix generic common side effects of lasix how to administer furosemide iv
lasix side effect furosemide tablets for sale mag 3 renal scan with lasix what is lasix prescribed for
side effects azithromycin zithromax without a script how long does azithromycin last what can azithromycin be used for
azithromycin interactions azithromycin 1000 mg buy chlamydia symptoms after treatment azithromycin what does azithromycin cover
ivermectin durvet ivermectin 3mg tablet ivermectin 1.87 paste for humans toxic ivermectin paste kills what worms
ivermectin mange stromectol 3mg cost ivermectin paste dosage for dogs when does ivermectin start to work on chickens
Please keep us up to datee like this. Thanks
for sharing…
free ventolin inhaler ventolin pills does albuterol help with coronavirus what happens when you have too many sprays of ventolin
ventolin covid 19 albuterol 0.5 mg what are the side effects of albuterol how do you use a ventolin inhaler
Thanks for your publiction. Another issue is that to be a photographer entails not only problem in catching award-winning photographs but hardships in establishing the best digicam suited to your requirements and most especially issues in maintaining the caliber of your camera. This can be very accurate and evident for those photographers that are into capturing this nature’s exciting scenes : the mountains, the particular forests, the actual wild or even the seas. Visiting these exciting places undoubtedly requires a dslr camera that can live up to the wild’s nasty settings.
Trulife Distribution – Nutrition Distribution helps our clients achieve success in a complex, competitive retail environment. Our team of nutrition industry experts takes care of everything from importation compliance to marketing, sales and distribution at the ground level. There is no need to navigate the complicated intricacies of the American market when we have already done the work. Let us use our experience to expand your brand and put your product into the hands of American consumers. https://trulifedist.com/
It’s perfect time to make some plans for the future and it’s time to be happy. I have read this post and if I could I want to suggest you some interesting things or tips. Perhaps you can write next articles referring to this article. I wish to read more things about it!
One more thing. I do believe that there are numerous travel insurance web pages of reputable companies that permit you to enter holiday details and obtain you the quotations. You can also purchase this international holiday insurance policy on the internet by using your own credit card. All you should do is usually to enter all your travel particulars and you can be aware of the plans side-by-side. Simply find the program that suits your financial allowance and needs after which it use your bank credit card to buy that. Travel insurance on the internet is a good way to begin looking for a respected company to get international holiday insurance. Thanks for revealing your ideas.
Hiya, I am really glad I have found this info. Nowadays bloggers publish just about gossips and internet and this is actually frustrating. A good site with interesting content, that is what I need. Thanks for keeping this website, I will be visiting it. Do you do newsletters? Can’t find it.
Good Afternoon everyone , can anyone suggest where I can buy Peppermint CBD Tincture By Urth CBD?