function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Swati BhaipSwati Bhaip 

CustomField

How to create custom field on Lead using Rest API java program
Abhinav GuptaAbhinav Gupta
You can use Tooling API or Metadata API to create Custom Field. Tooling API is having some bug in creating custom field (which might be resolved as of now). So best would be to use Metadata SOAP API for the same. 

This open source project (https://github.com/financialforcedev/apex-mdapi) is an Apex wrapper on Metadata API. You can learn from here and doing the same via Java stubs should be simple then. I also hope you are reading Metadata API docs (http://www.salesforce.com/us/developer/docs/api_meta/api_meta.pdf).

Here is a code snippet via Apex Metadata API wrapper (https://github.com/financialforcedev/apex-mdapi) to create custom field

public static void createField()
    {
        MetadataService.MetadataPort service = createService();     
        MetadataService.CustomField customField = new MetadataService.CustomField();
        customField.fullName = 'Test__c.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]);
    }
This example is pretty close to what you will get in Java stubs, so should be good enough to get you going. 

Please let me know if you need more pointers or help.