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 

Custom field

I have witten the below code to create Lead Custom Field but it is not work means it will not found the resource .So Please help me to create Custom field
public void createField(String instanceUrl, String accessToken,PrintWriter writer)
{

final MetricRegistry metrics = new MetricRegistry();

// in your app setup, create a pool that's shared for the whole app
RestConnectionPool<Integer> pool = new RestConnectionPoolImpl<Integer>(metrics);



int accId=55;

String instanceUrl1 = instanceUrl.substring("https://".length());
pool.configureOrg(accId, instanceUrl1, accessToken);

RestConnection connection = pool.getRestConnection(accId);
SObject newLead = RestSObjectImpl.getNew("LeadCustomField");
newLead.setField("FieldLabel", "NewLabel");
newLead.setField("DataType", "Picklist");

SaveResult result = null;
try {
  result = connection.create(newLead);
} catch (IOException e) {
  // TODO Auto-generated catch block
  e.printStackTrace();
}
writer.write("Created a lead Custom field with id " + result.getId());
}