Comments (13)
There is no direct API to like create, update and delete. But you can use the retrieve call. Take a look at the Metadata Retrieve Demo, it's a little more complex but you can get any metadata information this way. However, for Picklist it seems this is supported via the Apex Describe API, take a look at this, http://blogs.developerforce.com/developer-relations/2008/12/using-the-metadata-api-to-retrieve-picklist-values.html
from apex-mdapi.
Hi ,
nope :( that not the solution ,
the post : http://blogs.developerforce.com/developer-relations/2008/12/using-the-metadata-api-to-retrieve-picklist-values.html
is just code to get picklist values of any picklist field .using apex describe I am way past that ..
In record Types ..
from apex-mdapi.
If you can retrieve the info you need via the Metadata API, you can use the Retrieve Demo code to get at Record Type, Custom Object, Custom Field and/or Layout information.
from apex-mdapi.
Did you get the Retrieve Demo working for your needs?
from apex-mdapi.
Sadly NO ,
Retrieve response only give high level info ..
not metadata describe to available value of any field :(
from apex-mdapi.
Have you tried to do a Retrieve for the Record Types?
Much like the Retrieve Demo is doing for Layout.
from apex-mdapi.
Yes , i tried that code itself , not on page ..cause it does not show anything on page . when EXPENDING ....
but i check response .. and it does not provide any Sobject token or details about fields
from apex-mdapi.
In MetadataRetrieveController.cls, I changed lines 47 and 80 to assign 'RecordType' instead of 'Layout' and it returned this for my test Record Type on Account. I think this is what you need yes?
<?xml version="1.0" encoding="UTF-8"?>
<CustomObject xmlns="http://soap.sforce.com/2006/04/metadata">
<recordTypes>
<fullName>Test1</fullName>
<active>true</active>
<description>Test 1</description>
<label>Test 1</label>
<picklistValues>
<picklist>AccountSource</picklist>
<values>
<fullName>Other</fullName>
<default>false</default>
</values>
<values>
<fullName>Partner Referral</fullName>
<default>false</default>
</values>
<values>
<fullName>Phone Inquiry</fullName>
<default>false</default>
</values>
<values>
<fullName>Purchased List</fullName>
<default>false</default>
</values>
<values>
<fullName>Web</fullName>
<default>false</default>
</values>
</picklistValues>
<picklistValues>
<picklist>Industry</picklist>
<values>
<fullName>Agriculture</fullName>
<default>false</default>
</values>
<values>
<fullName>Apparel</fullName>
<default>false</default>
</values>
<values>
<fullName>Banking</fullName>
<default>false</default>
</values>
<values>
<fullName>Biotechnology</fullName>
<default>false</default>
</values>
<values>
<fullName>Chemicals</fullName>
<default>false</default>
</values>
<values>
<fullName>Communications</fullName>
<default>false</default>
</values>
<values>
<fullName>Construction</fullName>
<default>false</default>
</values>
<values>
<fullName>Consulting</fullName>
<default>false</default>
</values>
<values>
<fullName>Education</fullName>
<default>false</default>
</values>
<values>
<fullName>Electronics</fullName>
<default>false</default>
</values>
<values>
<fullName>Energy</fullName>
<default>false</default>
</values>
<values>
<fullName>Engineering</fullName>
<default>false</default>
</values>
<values>
<fullName>Entertainment</fullName>
<default>false</default>
</values>
<values>
<fullName>Environmental</fullName>
<default>false</default>
</values>
<values>
<fullName>Finance</fullName>
<default>false</default>
</values>
<values>
<fullName>Food %26 Beverage</fullName>
<default>false</default>
</values>
<values>
<fullName>Government</fullName>
<default>false</default>
</values>
<values>
<fullName>Healthcare</fullName>
<default>false</default>
</values>
<values>
<fullName>Hospitality</fullName>
<default>false</default>
</values>
<values>
<fullName>Insurance</fullName>
<default>false</default>
</values>
<values>
<fullName>Machinery</fullName>
<default>false</default>
</values>
<values>
<fullName>Manufacturing</fullName>
<default>false</default>
</values>
<values>
<fullName>Media</fullName>
<default>false</default>
</values>
<values>
<fullName>Not For Profit</fullName>
<default>false</default>
</values>
<values>
<fullName>Other</fullName>
<default>false</default>
</values>
<values>
<fullName>Recreation</fullName>
<default>false</default>
</values>
<values>
<fullName>Retail</fullName>
<default>false</default>
</values>
<values>
<fullName>Shipping</fullName>
<default>false</default>
</values>
<values>
<fullName>Technology</fullName>
<default>false</default>
</values>
<values>
<fullName>Telecommunications</fullName>
<default>false</default>
</values>
<values>
<fullName>Transportation</fullName>
<default>false</default>
</values>
<values>
<fullName>Utilities</fullName>
<default>false</default>
</values>
</picklistValues>
<picklistValues>
<picklist>Ownership</picklist>
<values>
<fullName>Other</fullName>
<default>false</default>
</values>
<values>
<fullName>Private</fullName>
<default>false</default>
</values>
<values>
<fullName>Public</fullName>
<default>false</default>
</values>
<values>
<fullName>Subsidiary</fullName>
<default>false</default>
</values>
</picklistValues>
<picklistValues>
<picklist>Rating</picklist>
<values>
<fullName>Cold</fullName>
<default>false</default>
</values>
<values>
<fullName>Hot</fullName>
<default>false</default>
</values>
<values>
<fullName>Warm</fullName>
<default>false</default>
</values>
</picklistValues>
<picklistValues>
<picklist>Type</picklist>
<values>
<fullName>Channel Partner %2F Reseller</fullName>
<default>false</default>
</values>
<values>
<fullName>Customer - Channel</fullName>
<default>false</default>
</values>
<values>
<fullName>Customer - Direct</fullName>
<default>false</default>
</values>
<values>
<fullName>Installation Partner</fullName>
<default>false</default>
</values>
<values>
<fullName>Other</fullName>
<default>false</default>
</values>
<values>
<fullName>Prospect</fullName>
<default>false</default>
</values>
<values>
<fullName>Technology Partner</fullName>
<default>false</default>
</values>
</picklistValues>
</recordTypes>
from apex-mdapi.
YEP ;
Looks quite correct ,
I will explore more and reply you back ;
Thanks LOT ..
from apex-mdapi.
Hi,
I'm trying to find the solution for the above problem. i did it by reading metadata for record type -
MetadataService.RecordType rt = (MetadataService.RecordType ) service.readMetadata('RecordType', new String[] { 'object.Record_type' }).getRecords()[0];
rt.picklistValues.add(mrt);
then tried updating it with this line -
List<MetadataService.SaveResult> saveResult1 = service.updateMetadata(
new MetadataService.Metadata[] { rt });
It says 'IO Exception: Read Time out'. Though it gives an exception, new picklist value got added to selected picklist list without removing old ones. I don't know, whether to continue with this approach b'coz it gives desired output, besides giving an exception.
from apex-mdapi.
Yes the web service request itself will have completed, the error means Apex gave up waiting for it, as Salesforce governors kicked in, as per this, https://www.salesforce.com/us/developer/docs/apexcode/Content/apex_gov_limits.htm, its 120 seconds. You can try looking at this however, https://help.salesforce.com/apex/HTViewSolution?id=000206743&language=en_US
from apex-mdapi.
Hi,
I am trying to update picklist values of 2 picklist fields on Product record types. Below is my code:
MetadataService.Metadata[] metadataToUpdate = new List<MetadataService.Metadata>();
FOR(RecordType rt : [SELECT Id, Name, DeveloperName, isActive, sObjectType FROM RecordType WHERE sObjectType = 'Product2']){
MetadataService.RecordType objRT = new MetadataService.RecordType();
objRT.active = rt.IsActive;
objRT.label = rt.Name;
objRT.fullName = rt.DeveloperName;
MetadataService.RecordTypePicklistValue rtplv1 = new MetadataService.RecordTypePicklistValue();
rtplv1.picklist = 'Aircraft_1__c';
rtplv1.values = plvList;
MetadataService.RecordTypePicklistValue rtplv2 = new MetadataService.RecordTypePicklistValue();
rtplv2.picklist = 'Aircraft_2__c';
rtplv2.values = plvList;
lstRtPlv = new List<MetadataService.RecordTypePicklistValue>{rtplv1,rtplv2};
rt.picklistValues = lstRtPlv;
metadataToUpdate.add(rt);
}
List<MetadataService.SaveResult> results1 = service.updateMetadata(metadataToUpdate);
MetadataServiceExamples.handleSaveResults(results1[0]);
This has to happen in a trigger so I have kept this code in future method. But the apex job fails with following error: First error: Error occured processing component Product2.NetJets_Card_Product. duplicate value found: duplicates value on record with id: (DUPLICATE_VALUE).
I confirmed the values being adding up contains no duplicates.
What is wrong?
from apex-mdapi.
Firstly its probably better if you open a new issue, as this doesn't appear related to this now closed issue. Can you also paste the code into the new issue using code style its much easier to read.
from apex-mdapi.
Related Issues (20)
- Help article to use named credentials with wrapper has been removed HOT 1
- Generate an Apex from WSDL
- GlobalValueSetTranslation HOT 2
- Update search layout task, event, activity HOT 1
- System.CalloutException: Web service callout failed: Unable to parse callout response. Apex type not found for element customizeSetup
- Apex Wrapper Metadata API Takes Time to Reflect the Change
- Can't create in production org
- Can't create a sharing rule HOT 2
- GlobalValueSetTranslation
- Can we create ApexClass natively? Any Example? HOT 1
- UserInfo.getSessionId() makes this unusable in packaged code HOT 2
- How do we update multiple profiles at once?
- LightningComponentBundle (LWC): reading/creating/updating
- Creating Apex Trigger
- Creating a MultiPicklist HOT 2
- System.CalloutException: Web service callout failed: Unable to parse callout response. Apex type not found for element includeRecordsOwnedByAll
- How To get Picklist Value according to record type for a custom object HOT 3
- Can anyone suggest on how to read the flexipage? HOT 7
- Issue retrieving layout metadata for object via Metadata API HOT 1
- Row Lock Error - Updating the Picklist values in the Customer field and RecordTypes
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from apex-mdapi.