You have not shared the JS. I am sharing the apex code to update the multiple fields using MetadataApi.
MetadataService.MetadataPort service = MetadataServiceExamples.createService();
MetadataService.CustomField customField = new MetadataService.CustomField();
customField.fullName = 'Contact.Change__c';
customField.label='Change__c Changed';
customField.type_x = 'Text';
customField.length = 52;
MetadataService.CustomField customField1 = new MetadataService.CustomField();
customField1.fullName = 'Contact.LookupField__c';
customField1.label='LookupField Changed';
customField1.type_x = 'Lookup';
customField1.referenceTo = 'Account';
customField1.relationshipLabel = 'Account';
customField1.relationshipName = 'Account';
List<MetadataService.SaveResult> results =
service.updateMetadata(
new MetadataService.Metadata[] { customField,customField1 });
You can not change the Label of the Standard field it'll throw Field_integrity_exception
Only custom fields label will be changed.
To update the picklist you need to do some additional changes in MetadataService class -
Replace
public virtual class CustomValue extends Metadata {
public String color;
public Boolean default_x;
public String description;
public Boolean isActive;
public String label;
}
With -
public virtual class CustomValue extends Metadata {
public String type = 'CustomValue';
public String fullName;
private String[] fullName_type_info = new String[]{'fullName',SOAP_M_URI,null,'0','1','false'};
public String color;
public Boolean default_x;
public String description;
public Boolean isActive;
public String label;
private String[] color_type_info = new String[]{'color',SOAP_M_URI,null,'0','1','false'};
private String[] default_x_type_info = new String[]{'default',SOAP_M_URI,null,'1','1','false'};
private String[] description_type_info = new String[]{'description',SOAP_M_URI,null,'0','1','false'};
private String[] isActive_type_info = new String[]{'isActive',SOAP_M_URI,null,'0','1','false'};
private String[] label_type_info = new String[]{'label',SOAP_M_URI,null,'0','1','false'};
private String[] apex_schema_type_info = new String[]{SOAP_M_URI,'true','false'};
private String[] field_order_type_info = new String[]{'fullName','color','default_x','description','isActive','label'};
}
MetadataService.MetadataPort service = MetadataServiceExamples.createService();
MetadataService.CustomField customField = new MetadataService.CustomField();
customField.fullName = 'Contact.Level__c';
customField.label = 'picklist 1';
customField.type_x = 'Picklist';
// Define the Value Set and Value Set Definitions
MetadataService.ValueSet vs = new MetadataService.ValueSet();
MetadataService.ValueSetValuesDefinition vd = new MetadataService.ValueSetValuesDefinition();
// Define the picklist values
List<MetadataService.CustomValue> customValues = new List<MetadataService.CustomValue>();
MetadataService.CustomValue cv1 = new MetadataService.CustomValue();
cv1.label = 'One';
cv1.fullName = 'One';
cv1.isActive = true;
cv1.default_x = false;
customValues.add(cv1);
MetadataService.CustomValue cv2 = new MetadataService.CustomValue();
cv2.label = 'Two';
cv2.fullName = 'Two';
cv2.isActive = true;
cv2.default_x = true;
customValues.add(cv2);
vd.value = customValues;
vd.sorted = true;
vs.valueSetDefinition = vd;
// Use valueSet instead of Picklist
customField.valueSet = vs;
List<MetadataService.SaveResult> results =
service.updateMetadata(
new MetadataService.Metadata[] { customField });
So you only need to add the customFields variables in the MetadataService.Metadata[].
I hope this will help you out.