function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
sushanto_dodosushanto_dodo 

How to set object permissions using ANT migration toolkit for Salesforce

Can someone kindly provide an outline on how can we set object permissions for a profile using ANT migration toolkit for Salesforce?

 

Satish_SFDCSatish_SFDC

Hi Sushanto,

In order to change the Object Permissions in one or more profiles, you will have to first retrieve the object along with the profiles.

 

For instance, my package.xml to retrieve the files will be as follows:

 

<?xml version="1.0" encoding="UTF-8"?>
<Package xmlns="http://soap.sforce.com/2006/04/metadata">
    <types>
        <members>Test__c</members>
        <name>CustomObject</name>
    </types>
    <types>
        <members>*</members>
        <name>Profile</name>
    </types>
    <version>27.0</version>
</Package>

 

This will give me all the Profiles metadata along with the object (Test__c).  If i open any profile metadata file, this is how it looks.

 

<?xml version="1.0" encoding="UTF-8"?>
<Profile xmlns="http://soap.sforce.com/2006/04/metadata">
    <fieldPermissions>
        <editable>true</editable>
        <field>Test__c.Contact__c</field>
        <readable>true</readable>
    </fieldPermissions>
    <fieldPermissions>
        <editable>true</editable>
        <field>Test__c.Opportunity__c</field>
        <readable>true</readable>
    </fieldPermissions>
    <fieldPermissions>
        <editable>true</editable>
        <field>Test__c.User__c</field>
        <readable>true</readable>
    </fieldPermissions>
    <objectPermissions>
        <allowCreate>false</allowCreate>
        <allowDelete>false</allowDelete>
        <allowEdit>false</allowEdit>
        <allowRead>false</allowRead>
        <modifyAllRecords>false</modifyAllRecords>
        <object>Test__c</object>
        <viewAllRecords>false</viewAllRecords>
    </objectPermissions>
    <userLicense>Salesforce</userLicense>
</Profile>

 

In the profile file, you will have to change the values under <objectPermissions> tag. Once saved, you can then deploy the profile along with the object file. You can use the same package.xml file, you used to retrieve.

 

Hope this helps. Let me know if you have any queries.

 

Regards,

Satish Kumar


Please mark my answer as a solution if it was helpful so it is available to others as a proper solution.
If you felt I went above and beyond, please give me Kudos by clicking on the star icon.