• gkreddy
  • NEWBIE
  • 0 Points
  • Member since 2016

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 3
    Questions
  • 2
    Replies
Hello,

I have a requirement to set custom picklist values from product objects with all the active products.
The picklist values always need to sync with product data incase of any additions or deletion on product object.

I have written below code to add picklist value to custom field. There are no compile errors but the value is not inserted as picklist value after running the code.

Can you tell what am doing wrong in the below code?


public class BU_MetadataAPI {

    
   // @future (callout = true)
    public static void AddValues()
    {
        String picklistapiname = 'Contact.testPicklist__c'    ;
        MetadataService.MetadataPort service = createService();    
        //MetadataService.CustomField customField = new MetadataService.CustomField();
        MetadataService.CustomField customField = (MetadataService.CustomField) service.readMetadata('CustomField', new String[] { picklistapiname}).getRecords()[0];
        
        System.debug ('Custom Field : '+customField);
        
        //Add values
        List<MetadataService.CustomValue> values = new List<MetadataService.CustomValue>();
        MetadataService.CustomValue v1 = new MetadataService.CustomValue();
        v1.fullName = 'SegmentA';
        v1.description = 'segmentA';
        v1.isActive = true;
        values.add(v1);
        
        //valueSetDefinition
        MetadataService.ValueSetValuesDefinition vsd = new MetadataService.ValueSetValuesDefinition();
        vsd.value = values;
        vsd.sorted = true;
        
        //valueSet
        MetadataService.ValueSet vs = new MetadataService.ValueSet();
        vs.valueSetDefinition = vsd;

        //Set valueSet
        customField.valueSet = vs;
        
        // Update Custom Field
        MetadataService.SaveResult saveResult = service.updateMetadata( new MetadataService.Metadata[] { customField })[0];  
    }
     
    public static MetadataService.MetadataPort createService()
    {
        MetadataService.MetadataPort service = new MetadataService.MetadataPort();
        service.SessionHeader = new MetadataService.SessionHeader_element();
        service.SessionHeader.sessionId = UserInfo.getSessionId();
        return service;    
    }
 
    
}
Hello,
I have requirement to load the picklist dynamically after some button click using other input fields.
Is it possible in visualforce?

Thank you
The visual force have two fields : 1 st one is text field and other one is a picklist.

The picklist need to be loaded dynamically based on input text field. 
Is it possible in visualforce ? I am good to load the data on button click as well.

Thanks in advance for any inputs.
Hello,
I have requirement to load the picklist dynamically after some button click using other input fields.
Is it possible in visualforce?

Thank you
The visual force have two fields : 1 st one is text field and other one is a picklist.

The picklist need to be loaded dynamically based on input text field. 
Is it possible in visualforce ? I am good to load the data on button click as well.

Thanks in advance for any inputs.