You need to sign in to do that
Don't have an account?

Metadata api - Picklist Value Sets
Hi,
Does anybody have working code to retrieve and upsert picklist value sets ?
Can't get it to work, this is my current code :
readMetadata returns :
[CustomValue [Metadata fullName='A02'
]
color='null'
_default='false'
description='null'
isActive='false'
label='A02'
]
]
The picklist value is active so i would expect :
[CustomValue [Metadata fullName='A02'
]
color='null'
_default='false'
description='null'
isActive='true'
label='A02'
]
]
Later when i execute the upsert with :
I get the error output :
Error encountered while updating: Application
Error message: CustomField not found.
Does anybody have working code to retrieve and upsert picklist value sets ?
Can't get it to work, this is my current code :
private GlobalValueSet readGlobalValueSet(String picklist) throws Exception { GlobalValueSet values = new GlobalValueSet(); MetadataConnection metadataConnection = sfmcon.getConnection(); ReadResult readResult = metadataConnection.readMetadata("GlobalValueSet", new String[] {picklist}); //log.info(readResult.toString()); Metadata[] mdInfo = readResult.getRecords(); if (mdInfo.length == 1) { values = (GlobalValueSet) mdInfo[0]; } else { log.info("None or multiple components"); } return values; }
readMetadata returns :
[CustomValue [Metadata fullName='A02'
]
color='null'
_default='false'
description='null'
isActive='false'
label='A02'
]
]
The picklist value is active so i would expect :
[CustomValue [Metadata fullName='A02'
]
color='null'
_default='false'
description='null'
isActive='true'
label='A02'
]
]
Later when i execute the upsert with :
MetadataConnection metadataConnection = sfmcon.getConnection(); SaveResult[] results = metadataConnection.updateMetadata(new Metadata[] {repair});
I get the error output :
Error encountered while updating: Application
Error message: CustomField not found.
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
thx for your response.
The code i supplied is java using the metadata api.
Nevertheless :
I tried your code in apex and got the error :
Invalid type: MetadataService.MetadataPort
it is apex code not java.
You can access metadata directly
Find MetaData API Wsdl
Go to setup--->API-->Metadata WSDL
Click on the link below to download a Metadata WSDL file.
Generate Metadata WSDL---->
How to geneate Apex from WSDl-->Setup-->apex classes--->Geneate from Wsdl
First you to generate apex code for meta data API using wsdl file of metadata
to use MataData is API for apex first you have genearte apex code from matadata wsdl file.
https://developer.salesforce.com/blogs/engineering/2017/05/introducing-apex-metadata-api.html
https://help.salesforce.com/articleView?id=code_wsdl_to_package.htm&type=0
you can also use apex metadata class from GitHUB-->Copy code from github and paste into apex classes(New Class)
https://github.com/financialforcedev/apex-mdapi/tree/master/apex-mdapi/src/classes
Further tip. I created a formula column in my Excel spreadsheet to generate the <customValue> component for each picklist value in an Excel table which I then copied into the xml (after removing the extraneous quotes("). In Excel, the formula was: You could do the same using the Force IDE too.