0

I perform the following steps.

In salesforce classic ui add a custom field of type Text to Account object.

Retrieve this single field with readMetadata request (instead of "---" there goes real access token):

<soapenv:Envelope xmlns="http://soap.sforce.com/2006/04/metadata" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
  <soapenv:Header>
    <SessionHeader>
      <sessionId>---</sessionId>
    </SessionHeader>
  </soapenv:Header>
  <soapenv:Body>
    <readMetadata>
      <type>CustomField</type>
      <fullNames>Account.text__c</fullNames>
    </readMetadata>
  </soapenv:Body>
</soapenv:Envelope>

The response is:

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns="http://soap.sforce.com/2006/04/metadata" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <soapenv:Body>
    <readMetadataResponse>
      <result>
        <records xsi:type="CustomField">
          <fullName>Account.text__c</fullName>
          <externalId>false</externalId>
          <label>text</label>
          <length>50</length>
          <required>false</required>
          <trackFeedHistory>false</trackFeedHistory>
          <type>Text</type>
          <unique>false</unique>
        </records>
      </result>
    </readMetadataResponse>
  </soapenv:Body>
</soapenv:Envelope>

Delete the field in UI or by sending deleteMetadata request.

Using the contents of previously recieved readMetadataResponse, recreate the field by sending createMetadata request:

<soapenv:Envelope xmlns="http://soap.sforce.com/2006/04/metadata" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
  <soapenv:Header>
    <SessionHeader>
      <sessionId>---</sessionId>
    </SessionHeader>
  </soapenv:Header>
  <soapenv:Body>
    <createMetadata>
      <metadata xsi:type="CustomField">
        <fullName>Account.text__c</fullName>
        <externalId>false</externalId>
        <label>text</label>
        <length>50</length>
        <required>false</required>
        <trackFeedHistory>false</trackFeedHistory>
        <type>Text</type>
        <unique>false</unique>
      </metadata>
    </createMetadata>
  </soapenv:Body>
</soapenv:Envelope>

After doing so I can see this field again in sobject settings ui and in readMetadataResponse, but it is no longer listed in json response of REST endpoint

GET https://---.my.salesforce.com/services/data/v54.0/sobjects/Account/describe

and there's no UI input for this fields' value when creating a new Account record, so effectively it doesn't exist. It'll be great if there's any idea what is the reason.

1 Answer 1

2

Adding a field to an object does not automatically add Field Level Security to your profile, nor does it add it to any page layout. You'll need to add it to your profile and add it to a page layout, and then you'll see it

1
  • Thank you. Shall investigate how to preserve all this stuff via API.
    – Alexander
    Mar 18, 2022 at 10:17

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .