[SalesForce] Custom Field not visible, event when added to page layout

Rather new to Salesforce here, trying to set up some automated object and field creation through the SOAP API. Making a new custom object is no problem, making a new custom field is no problem, and I've discovered how to add a custom field to a layout.

However, every custom field I make through the API has visibility off for every profile. I was under the impression after doing some research that adding a field to the page layout allowed the API to view that field, but that doesn't seem to be the case. Even when a field is added to the layout, it doesn't appear when the object is described.

Is there any way to create a custom field through the SOAP API without having to manually set the visibility in the UI?

Best Answer

@keith-c is right that the layouts work in combination with the field security set in the profile. The use case for that is two users with different profiles who share the same layout. One profile can access Field A while the other profile cannot. In this case, you don't have to build two different layouts.

If you're wanting to do this exclusively through the Metadata API, you'd need to also deploy modified versions of all your profiles which include the new field's visibility settings.

Here's an example of the elements you'd need in the profile:

<fieldPermissions>
    <editable>true</editable>
    <field>Contact.Gender__c</field>
    <readable>true</readable>
</fieldPermissions>

Note that it's probably a good idea to retrieve the profiles first before editing them. If you are working with an older copy of the profile on disk you might wind up deploying the older version and overwriting other changes made to the profile.

Here's the relevant Metadata API docs: http://www.salesforce.com/us/developer/docs/api_meta/Content/meta_profile.htm#profilefieldlevelsecurity_title

Related Topic