There is managed package on dev org, developed by our team. Using Ant Migration Tool code was fetched from salesforce.

<target name="retrievePkg">
      <sf:retrieve username="${sf.username}" password="${sf.password}" sessionId="${sf.sessionId}" serverurl="${sf.serverurl}" maxPoll="${sf.maxPoll}" retrieveTarget="retrievePkg" packageNames="${sf.pkgName}"/>

Then i tried to deploy this code to my personal dev org using

<target name="deployCode">
      <sf:deploy username="${sf.personalusername}" password="${sf.personalpassword}" serverurl="${sf.serverurl}" maxPoll="${sf.maxPoll}" deployRoot="retrievePkg" rollbackOnError="true">

BUT it failed with numerous of errors. For example:

  • [sf:deploy] 2. labels/CustomLabels.labels (Save) -- Error: Cannot create a new component with the namespace: ***. Only components in the same namespace as the organization can be created through the API (line 395, column 13)
  • [sf:deploy] 77. components/CallComments.component -- Error: Cannot modify managed object: entity=ApexComponent, component=099280000008jxQ, field=Markup, state=MANAGED_INSTALLED: newValue='
  • You can transfer managed package source code from a namespace org to a non-namespace org only if you have managed to avoid adding the namespace to any of the code. This is hard to do unless you use something like Jenkins to continuously push the code into a non-namespace org to check.
    – Keith C
    Aug 31, 2015 at 9:57

1 Answer 1


You cannot directly use ANT to deploy managed packaged components.
For deploying managed packages you have to use some ant macro like this:

    <macrodef name="installPackage" description="Installs the given managed package">
        <attribute name="namespace" description="Namespace of managed package to install."/>
        <attribute name="version" description="Version of managed package to install."/>
        <attribute name="packagePassword" description="Password used to install the pacakge. Optional." default=""/>
        <attribute name="username" description="Salesforce user name."/>
        <attribute name="password" description="Salesforce password."/>
            <!-- Generate optional <password> element? -->
            <if><equals arg1="@{packagePassword}" arg2=""/>
                <then><property name="passwordElement" value=""/></then>
                <else><property name="passwordElement" value="<password>@{packagePassword}</password>"/></else>
            <!-- Generate working folder and metadata files representing the package to install -->
            <delete dir="${basedir}/installdeploy"/>
            <mkdir dir="${basedir}/installdeploy"/>
            <mkdir dir="${basedir}/installdeploy"/>           
            <mkdir dir="${basedir}/installdeploy/installedPackages"/>
            <echo file="${basedir}/installdeploy/package.xml"><![CDATA[<Package xmlns="http://soap.sforce.com/2006/04/metadata"><types><members>@{namespace}</members><name>InstalledPackage</name></types><version>28.0</version></Package>]]></echo>
            <echo file="${basedir}/installdeploy/installedPackages/@{namespace}.installedPackage"><![CDATA[<InstalledPackage xmlns="http://soap.sforce.com/2006/04/metadata"><versionNumber>@{version}</versionNumber>${passwordElement}</InstalledPackage>]]></echo>
            <sf:deploy deployRoot="${basedir}/installdeploy" username="@{username}" password="@{password}"/>

You must log in to answer this question.

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