Giter Site home page Giter Site logo

Comments (13)

afawcett avatar afawcett commented on July 30, 2024

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.

mohit-address avatar mohit-address commented on July 30, 2024

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.

afawcett avatar afawcett commented on July 30, 2024

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.

afawcett avatar afawcett commented on July 30, 2024

Did you get the Retrieve Demo working for your needs?

from apex-mdapi.

mohit-address avatar mohit-address commented on July 30, 2024

Sadly NO ,
Retrieve response only give high level info ..
not metadata describe to available value of any field :(

from apex-mdapi.

afawcett avatar afawcett commented on July 30, 2024

Have you tried to do a Retrieve for the Record Types?

Much like the Retrieve Demo is doing for Layout.

from apex-mdapi.

mohit-address avatar mohit-address commented on July 30, 2024

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.

afawcett avatar afawcett commented on July 30, 2024

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.

mohit-address avatar mohit-address commented on July 30, 2024

YEP ;
Looks quite correct ,
I will explore more and reply you back ;
Thanks LOT ..

from apex-mdapi.

yellajosyulaP avatar yellajosyulaP commented on July 30, 2024

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.

afawcett avatar afawcett commented on July 30, 2024

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.

Sudha613 avatar Sudha613 commented on July 30, 2024

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.

afawcett avatar afawcett commented on July 30, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.