+ Start a Discussion
Puja Patil 13Puja Patil 13 

Invalid type: MetadataService.MetadataPort

Hi all,
 I want to create new field dynamically , I have written following apex class.
But it gives erroe as " Invalid type: MetadataService.MetadataPort "

public class CustomField1 {
    String sessionID = UserInfo.getSessionId();
    public static void createField()
    {
        MetadataService.MetadataPort service = createService();     
        MetadataService.CustomField customField = new            MetadataService.CustomField();
        customField.fullName = 'Account.TestField__c';
        customField.label = 'Test Field';
        customField.type_x = 'Text';
        customField.length = 42;
        List<MetadataService.SaveResult> results =    service.createMetadata(
                new MetadataService.Metadata[] { customField });                
        handleSaveResults(results[0]);
    }
}

If anyone knows..Please help me..
bob_buzzardbob_buzzard
This looks like you are trying to use the financial force metadata api via apex. Have you imported all of the classes from that library?

In case you've copied code from elsewhere without realising it's a library, you can find it at:

https://github.com/financialforcedev/apex-mdapi