2

I have a problem creating a LongTextArea custom field. I don't understand what is wrong, if it's actually not created or not visible as a field.

This is my code:

    CustomField customField = new CustomField();
    customField.setFullName(fullName);
    customField.setDescription(description);
    customField.setType(fieldType);
    customField.setLabel(label);
    customField.setRequired(true);

    if (fieldType.equals(FieldType.LongTextArea)) {
        customField.setLength(32000);
        customField.setVisibleLines(30);
    }

This is wrong? Any help will be helpful, thank you.

2

Try this. Replace Test__c with your custom object api name.

MetadataService.MetadataPort service = createService();     
MetadataService.CustomField customField = new MetadataService.CustomField();
customField.fullName = 'Test__c.LongTextAreaField__c';
customField.label = 'Long Text Area Field';
customField.type_x = 'LongTextArea';
customField.length = 32000;
customField.visibleLines = 3;
MetadataService.AsyncResult[] results = service.create(new List<MetadataService.Metadata> { customField });
3
  • Using metadata api it's what i am doing. it does not throw any errors on create :( Aug 25 '16 at 11:14
  • Did this work for you?
    – Reshma
    Aug 25 '16 at 11:39
  • 1
    I had to delete some lines: customField.setTrackFeedHistory(true); customField.setTrackHistory(true); customField.setRequired(true); and then it worked Aug 25 '16 at 12:22

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.