+ Start a Discussion
Denis VakulishinDenis Vakulishin 

[Metadata API] Adding Custom field to object

Hi all,
I' trying to add custom field to object via Metadata API. But I'm getting FIELD_INTEGRITY_EXCEPTION (Could not resolve standard field's name).
I have no clue why this can happen.
Here's some of my .Net code
//Initialization
var cf = new CustomField()
          {
            fullName = "object__c.testfield__c",
            type = FieldType.Text,
            label = "Field",
            length = 42,
            lengthSpecified = true,
            description = "Test",
          });

Creation 
var res = await client.createMetadataAsync(new SessionHeader() { sessionId = loginResp.result.sessionId }, null, new Metadata[]{cf});


Thanks in advance.
Best Answer chosen by Denis Vakulishin
Denis VakulishinDenis Vakulishin
I found the problem, I need to add 
typeSpecified = true,

to the CustomField Initializtion

All Answers

Denis VakulishinDenis Vakulishin
Also here resulted SOAP Envelope

<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
    <s:Header>
        <h:SessionHeader xmlns:h="http://soap.sforce.com/2006/04/metadata" xmlns="http://soap.sforce.com/2006/04/metadata" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
            <sessionId>sessionIdGoesHere</sessionId>
        </h:SessionHeader>
    </s:Header>
    <s:Body xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
        <createMetadata xmlns="http://soap.sforce.com/2006/04/metadata">
            <metadata xsi:type="CustomField">
                <fullName>Object__c.TestField__c</fullName>
                <description>Test</description>
                <label>Field1</label>
                <length>42</length>
            </metadata>
        </createMetadata>
    </s:Body>
</s:Envelope>


Denis VakulishinDenis Vakulishin
I found the problem, I need to add 
typeSpecified = true,

to the CustomField Initializtion
This was selected as the best answer