• TeaJay
  • NEWBIE
  • 0 Points
  • Member since 2009

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
    Questions
  • 1
    Replies
Hi,
 
Im trying to create a TEXT field on a custom object using the metaData API.
 
It keeps failing stating that im trying to specify precision for a text field but I'm not.
 
Can anybody help?
 
Here is my code
 

private void createCustomField(CustomObject cObj)

{

//Verify that we are already authenticated, if not

//call the login function to do so

if (!loggedIn)

{

if (!login())

return;

}

try

{

string fieldName = "NewField";

CustomField cf = new CustomField();

cf.description = "Test Field";

cf.fullName = cObj.fullName + "." + fieldName + "__c";

cf.label = fieldName.ToString();

cf.type = FieldType.Text;

cf.length = 250;

MetadataService mBinding = new MetadataService();

mBinding.SessionHeaderValue = new basicSample_cs.apexMetadata.SessionHeader();

mBinding.SessionHeaderValue.sessionId = binding.SessionHeaderValue.sessionId;

mBinding.Url = binding.Url.Replace(@"/c/", @"/m/");

AsyncResult asyncResult = mBinding.create(new Metadata[] { cf })[0];

while (asyncResult.state == AsyncRequestState.InProgress)

{

Thread.Sleep(asyncResult.secondsToWait * 1000);

Console.WriteLine("Checking status...\n\tState:" + asyncResult.state + "\n\tStatus: " + asyncResult.statusCode + "\n\tSeconds to wait: " + asyncResult.secondsToWait);

asyncResult = mBinding.checkStatus(new String[] { asyncResult.id })[0];

}

if (asyncResult.state == AsyncRequestState.Completed)

{

Console.Write("Custom field has been created.");

Console.ReadLine();

}

}

catch (Exception ex)

{

Console.WriteLine("\nFailed to create object: \n"

+ ex.Message);

Console.WriteLine("\nHit return to continue...");

Console.ReadLine();

}

}