We've visited the following link, and followed the examples/instructions to no avail.
https://developer.salesforce.com/forums/?id=906F0000000AVifIAG
We originally utilized the CRUD-based SOAP API to create a custom field on a standard object, such as Contact. This worked fine. However, we could not pull that field via the API because it did not have permissions set on it for any of the profiles.
Then, we started researching. The best example is through the link above, and we discovered we could only upload profile changes via the File-based SOAP API for Metadata. So we attempted to do that. First we tried modifying permissions and uploading for the custom field we created via CRUD, but then we switched to full File-based SOAP API methodology to create the custom field as well as set permissions for it on all Profiles.
Such was the case in the example above. It did not work. We got to the point where Salesforce would tell us "The deploy was successful" - But no custom fields were created, no permissions set, and we did not receive any error messages.
Our code builds a ZIP file in the same structure as the example above. As I mentioned, we don't get any errors. But we do not see any deployed changes either.
We've even checked this out, and is also essentially what we were trying to do: Set Field Level security for profile using meta-data api
Our folder structure for the ZIP file:
public/
xml/
<clientId>/
DeployFiles/
objects/
Contact.object
profiles/
<profilename>.profile
<profilename>.profile
<profilename>.profile
...etc
package.xml
We ZIP DeployFiles, so the ZIP file contains the objects folder, profiles folder, package.xml file, etc. I unzipped it after just to make sure, and all our changes to the xml files are there. (.object and .profile are xml structures).
Our package.xml contains the following:
<?xml version="1.0" encoding="UTF-8" ?>
<Package xmlns="http://soap.sforce.com/2006/04/metadata">
<apiAccessLevel></apiAccessLevel>
<description></description>
<fullName></fullName>
<namespacePrefix></namespacePrefix>
<objectPermissions></objectPermissions>
<setupWeblink></setupWeblink>
<types>
<members>*</members>
<name>Profile</name>
</types>
<types>
<members>Contact.Create_Field_Metadata_API_Test__c</members>
<name>CustomField</name>
</types>
<version>32</version>
</Package>
Our Contact.object XML contains the following:
<?xml version="1.0" encoding="UTF-8" ?>
<CustomObject xmlns="http://soap.sforce.com/2006/04/metadata">
<deploymentStatus>Deployed</deploymentStatus>
<description></description>
<fields>
<fullName>Create_Field_Metadata_API_Test__c</fullName>
<description></description>
<label>Create Field Metadata API Test</label>
<type>Text</type>
<length>100</length>
</fields>
</CustomObject>
One of our profile examples (theres a ton of profile files included in the profiles folder):
<?xml version="1.0" encoding="UTF-8"?>
<Profile xmlns="http://soap.sforce.com/2006/04/metadata">
<custom>false</custom>
<userLicense>Salesforce</userLicense>
<userPermissions>
<enabled>true</enabled>
<name>AllowViewKnowledge</name>
</userPermissions>
<userPermissions>
<enabled>true</enabled>
<name>ApiEnabled</name>
</userPermissions>
<userPermissions>
<enabled>true</enabled>
<name>AssignTopics</name>
</userPermissions>
<userPermissions>
<enabled>true</enabled>
<name>ChatterEditOwnPost</name>
</userPermissions>
<userPermissions>
<enabled>true</enabled>
<name>ChatterFileLink</name>
</userPermissions>
<userPermissions>
<enabled>true</enabled>
<name>ChatterInternalUser</name>
</userPermissions>
<userPermissions>
<enabled>true</enabled>
<name>ChatterInviteExternalUsers</name>
</userPermissions>
<userPermissions>
<enabled>true</enabled>
<name>ChatterOwnGroups</name>
</userPermissions>
<userPermissions>
<enabled>true</enabled>
<name>ConvertLeads</name>
</userPermissions>
<userPermissions>
<enabled>true</enabled>
<name>CreateCustomizeFilters</name>
</userPermissions>
<userPermissions>
<enabled>true</enabled>
<name>CreateTopics</name>
</userPermissions>
<userPermissions>
<enabled>true</enabled>
<name>DistributeFromPersWksp</name>
</userPermissions>
<userPermissions>
<enabled>true</enabled>
<name>EditEvent</name>
</userPermissions>
<userPermissions>
<enabled>true</enabled>
<name>EditOppLineItemUnitPrice</name>
</userPermissions>
<userPermissions>
<enabled>true</enabled>
<name>EditReports</name>
</userPermissions>
<userPermissions>
<enabled>true</enabled>
<name>EditTask</name>
</userPermissions>
<userPermissions>
<enabled>true</enabled>
<name>EditTopics</name>
</userPermissions>
<userPermissions>
<enabled>true</enabled>
<name>EmailMass</name>
</userPermissions>
<userPermissions>
<enabled>true</enabled>
<name>EmailSingle</name>
</userPermissions>
<userPermissions>
<enabled>true</enabled>
<name>EnableNotifications</name>
</userPermissions>
<userPermissions>
<enabled>true</enabled>
<name>ExportReport</name>
</userPermissions>
<userPermissions>
<enabled>true</enabled>
<name>ImportPersonal</name>
</userPermissions>
<userPermissions>
<enabled>true</enabled>
<name>ManageCssUsers</name>
</userPermissions>
<userPermissions>
<enabled>true</enabled>
<name>MassInlineEdit</name>
</userPermissions>
<userPermissions>
<enabled>true</enabled>
<name>OverrideForecasts</name>
</userPermissions>
<userPermissions>
<enabled>true</enabled>
<name>RunReports</name>
</userPermissions>
<userPermissions>
<enabled>true</enabled>
<name>SelectFilesFromSalesforce</name>
</userPermissions>
<userPermissions>
<enabled>true</enabled>
<name>SendSitRequests</name>
</userPermissions>
<userPermissions>
<enabled>true</enabled>
<name>SubmitMacrosAllowed</name>
</userPermissions>
<userPermissions>
<enabled>true</enabled>
<name>ViewHelpLink</name>
</userPermissions>
<userPermissions>
<enabled>true</enabled>
<name>ViewSetup</name>
</userPermissions>
<fieldPermissions>
<hidden>false</hidden>
<readable>true</readable>
<editable>true</editable>
<field>Contact.Create_Field_Metadata_API_Test__c</field>
</fieldPermissions>
</Profile>
This is the result as seen in Salesforce:
Does anyone have a clue as to what we're doing wrong? Any help would be appreciated at this point, as we're hitting a brick wall with nowhere to go.
Some additional stuff I've tried just now-
Our application we're building utilized v32 API endpoints. The WSDL's were v27. I configured everything to use the latest API from Salesforce, v35. Still no-go. Set everything to v27, and using the CRUD-based SOAP API, I was able to create the field and its permissions would auto-set, so that works.
Until we find a solution for versions of the API above v28, I'm probably going to use v27 of the Metadata API but v35 of the Partner API. This makes it so we don't even have to utilize the file-based API.
Just saw this question, which asks the same thing as the first half of what we need, how to create the actual custom field on an object via the API. However, we are also looking to update / deploy permissions at the same time: Not able to create custom fields using deploy() call