1

i'm trying to add a new value to a picklist every time a trigger is executed, but now i'm stuck in front of a wall that i can't pass through due to the fact that i don't understand why i'm getting this error.

First error: Web service callout failed: WebService returned a SOAP Fault: '' is not valid for type xsd:boolean, should be '0', '1', 'true' or 'false' faultcode=soapenv:Client faultactor=

The error shows up on the last line of the class, on the upsertResult (I've also tried Update and doesn't work neither, I keep getting the same error)

i Copy also my Apex class and the trigger. Trigger:

trigger test on Maestros__c (after insert) {
System.debug('Llamo a actuar');
testerino.actuar(UserInfo.getSessionId());

}

Apex Class:

public class Testerino {
@future(callout=true) public static  void actuar(String UserID) {
    MetadataService.MetadataPort service = MetadataServiceExamples.createService(UserID);
    MetadataService.CustomField customField =
    (MetadataService.CustomField) service.readMetadata('CustomField',
    new String[] { 'Account.picklist__c' }).getRecords()[0];
    System.debug('He cogido el valor de customfieldcorrectamente');
    System.debug(customField);
    MetadataService.Picklist picklist = customField.picklist;
    List <MetadataService.PicklistValue> picklistValues = picklist.picklistValues;
    MetadataService.PicklistValue picklistvaluenuevo = new MetadataService.PicklistValue ();
    picklistvaluenuevo.fullName = 'TEST';
    System.debug(picklistValues);
    picklistValues.add(picklistvaluenuevo);
    picklist.picklistValues = picklistValues;
    customField.picklist = picklist;
    System.debug(picklist);
    MetadataService.UpsertResult[] results = service.UpsertMetadata(new MetadataService.Metadata [] {customField});
}

}

I would like just to know if this is just possible and I can add new values to my pickslist or not. If also someone can see if it's possible what am I missing that would be really nice, but i mainly just want to know if this is possible. The metadata Classes were downloaded from https://github.com/financialforcedev/apex-mdapi. And copied into the project ( i only modified 1 thing, added 1 creator class MetadataServiceExamples.createService(UserID), so i could pass it the UserID i got on the trigger (I do this because you can't get the UserID on @future methods.

Thanks for you attention.

5

you just miss one line

picklistvaluenuevo.default_x=false ;

public class Testerino {
@future(callout=true) public static  void actuar(String UserID) {
    MetadataService.MetadataPort service = MetadataServiceExamples.createService(UserID);
    MetadataService.CustomField customField =
    (MetadataService.CustomField) service.readMetadata('CustomField',
    new String[] { 'Account.picklist__c' }).getRecords()[0];
    System.debug('He cogido el valor de customfieldcorrectamente');
    System.debug(customField);

    MetadataService.Picklist picklist = customField.picklist;
    List <MetadataService.PicklistValue> picklistValues = picklist.picklistValues;
    MetadataService.PicklistValue picklistvaluenuevo = new MetadataService.PicklistValue ();
    picklistvaluenuevo.fullName = 'TEST';
    picklistvaluenuevo.default_x=false ;
    picklistValues.add(picklistvaluenuevo);
    picklist.picklistValues = picklistValues;
    customField.picklist = picklist;

    MetadataService.UpsertResult[] results = service.UpsertMetadata(new MetadataService.Metadata [] {customField});
}

I think this might be usefull for you if i am wrong then correct me.

| improve this answer | |
  • It Worked! I would never had realized that line of code missing by miself, actually made a lot of sense since it need a boolean value, but didn't knew a picklist value needs a default boolean. That was the key part. Thank you really much. Really apreciated. – Alexander Gimenez Feb 20 '15 at 11:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.