Comments (2)
Many thanks for this! I'll integrate it into the samples for sure! Thanks again!
from apex-mdapi.
hi @mohit-address @afawcett
Since picklist is depreciated I used valueset to create dependent fields using metadata API can anyone help me if there is anything missing in the below I am getting a null pointer
public static void createDependentPicklistField(){
MetadataService.MetadataPort service = new MetadataService.MetadataPort();
service.SessionHeader = new MetadataService.SessionHeader_element();
service.SessionHeader.sessionId = UserInfo.getSessionId();
/* MetadataService.CustomField customField2 = new MetadataService.CustomField();
customField2.fullName = 'lead.Controlling_Picklist__c';
customField2.label = 'Controlling Picklist';
customField2.type_x = 'Picklist';
MetadataService.SaveResult[] results2 = service.createMetadata(new List<MetadataService.Metadata> { customField2 }); */
MetadataService.CustomField customField = new MetadataService.CustomField();
customField.fullName = 'lead.dependent_picklist__c';
customField.label = 'Dependent Picklist';
customField.type_x = 'Picklist';
system.debug('L180'+customField);
MetadataService.ValueSet valuest = new MetadataService.ValueSet();
valuest.controllingField= 'Controlling_Picklist__c';
system.debug('controlling field at L185 is'+valuest.controllingField);
MetadataService.ValueSetValuesDefinition newValsetDef = new MetadataService.ValueSetValuesDefinition();
newValsetDef.sorted = false;
system.debug('L187'+newValsetDef);
MetadataService.CustomValue newItem = new MetadataService.CustomValue();
newItem.fullName = 'Dependent 0';
newItem.label = 'Dependent 0';
newItem.isActive = true;
newItem.default_x = true;
system.debug('L194'+newItem);
MetadataService.ValueSettings valsetting = new MetadataService.ValueSettings();
valsetting.controllingFieldValue = new list <string> {'Control Odd number'};
system.debug('L198'+valsetting);
newValsetDef.value.add(newItem);
valuest.valueSetDefinition = newValsetDef;
valuest.valueSettings.add(valsetting);
//Adding second picklist
MetadataService.CustomValue newItem2 = new MetadataService.CustomValue();
newItem2.fullName = 'Dependent 1';
newItem2.label = 'Dependent 1';
newItem2.isActive = true;
newItem2.default_x = false;
MetadataService.ValueSettings valsetting1 = new MetadataService.ValueSettings();
valsetting1.controllingFieldValue = new list <string> {'Control Odd number','Control Even number'};
newValsetDef.value.add(newItem2);
valuest.valueSetDefinition = newValsetDef;
valuest.valueSettings.add(valsetting1);
//MetadataService.AsyncResult[] results = service.createMetadata(new List<MetadataService.Metadata> { customField });
MetadataService.SaveResult[] results1 = service.createMetadata(new List<MetadataService.Metadata> { customField });
for (MetadataService.SaveResult objResult : results1) {
if (objResult.success) {
System.debug('Successfully updated.......123131313123');
}
else {
if(objResult.errors.size() > 0){
System.debug('eror : ' + objResult.errors[0].message);
}
}
}
}
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.