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
Keith654Keith654 

Reading complete profiles using the Metadata API or sf:retrieve for a customization project

I'd appreciate input on the following use case which I would assume is a fairly common one.

 

I am building a customization project that uses objects from an installed managed package. As this is a long-term project I'm keeping the customizations in SVN via the Eclipse Force IDE. So for example, additional data fields that I add are nicely handled via the (package.xml) CustomField metadata component type in that they can be extracted from the org and then committed to SVN. But I'm puzzled about how to handle profiles, be they edits of the managed package ones or new ones created for the customization project.

 

Based on the documentation and posts such as this Failed to retrieve custom profile to Eclipse 3.3, the parts of the profile that are returned when the Profile metadata component type is used are filtered by the other items being retrieved. But In my case what I need is all the profile settings, both those for the components in the managed package (because I'm customizing which fields etc from that managed package are being shown and how), plus the profile settings for my added fields. All I get by default are the latter ones which are a small fraction of the total set I need.

 

I note that although the wildcard matching for members (the "*") does not match components in the managed package it is possible to explicitly name the items (where the names have to include the namespace prefix) so by explicitly naming all the components in the managed package it might be possible to also retrieve all the profile settings. But that is a scarily fragile way to go and leaves you with an Eclipse project where 99% of the files are unwanted ones just requested to cheat the API.

 

The only work-around I can think of is to write some Java code that uses the Metadata API to first identify all the components (both in the managed package and in the customization project), then requests them all, but ultimately throws everything away except the profiles. This might only take a few hours to do, but it would take a while longer to test to be sure that all the profile settings were included.

 

So if I've missed an obvious way to do this or if you have any other insight please comment.

 

Thanks,

Keith

Keith654Keith654

I thought this might work as it nominally fetches content in one request from both the managed package (specified by package name) and the customization (specified in a package.xml):

 

<target name="retrieve">
    <taskdef name="sfretrieve" classname="com.salesforce.ant.RetrieveTask"
            classpathref="ant.additions.classpath"/>
    <echo message="retrieving from ${sf.username}"/>
    <sfretrieve
        username="${sf.username}"
        password="${sf.password}"
        serverurl="${sf.serverurl}"
        singlepackage="false"
        unpackaged="retrieveFolder/package.xml"
        retrievetarget="retrieveFolder"
        packagenames="My Managed Package Name"
        />
</target>

But the result was no profiles at all in the "retrieveFolder/My Managed Package Name" output (but most other content from the managed package) and the profiles in "retrieveFolder/unpackaged/profiles" just containing content related to "retrieveFolder/package.xml".

Keith654Keith654

Given the silence on this issue (does anyone who works for salesforce ever look at this forum?)  I went ahead and created an Ant task that makes two requests, one to get the managed package content (throwing away the pages etc) and then a second one using a package.xml created from the results of the first request with the namespace prefix added to get he profiles.

 

At first sight this seems to work but it'll be a while before I can confirm that all the profile settings are retrieved.

saasraysaasray

This post helped me to solve a problem, so I just wanted to clarify the workaround to make it easier for someone else to use.

 

Note that this doesn't seem to be possible with Eclipse (currently API 22.0 as I write).

 

With the Force.com deployment tool (Ant) you can retrieve the user profile settings for items that are in a package (including managed package).

 

This package.xml will get profile permissions for all profiles for the "Installed_Product__c" object in my package which has the namespace SVMXC:

 

 

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

 Below, note that the "unpackaged" attribute is used in the XML, even though the object is in a package. This is the trick. The namespace e.g. SVMXC__ was used to refer to the object as being in a package instead of using the "packageNames" in the build.xml file:

    <target name="retrieveUnpackaged">
      <mkdir dir="retrieveUnpackaged"/>
      <sf:retrieve username="${sf.username}" password="${sf.password}" serverurl="${sf.serverurl}" retrieveTarget="retrieveUnpackaged" unpackaged="unpackaged/package.xml"/>
    </target>

 This allows the profile meta data file to be retrieved at the same time as the object which is inside a package