0

I am trying to delete 2 Apex classes and 2 inactive Apex triggers from a production environment using the ANT Migration Tool and I am stone-walled by an INVALID_SESSION_ID error, but I suspect there's something more complicated going on here.

Looking for guidance. Any help on where to move forward from here would be greatly appreciated.

%ROOT%/ant-migration-tool/ant-salesforce.jar

%ROOT%/ant-migration-tool/build.xml (note: build.properties does contain my security token)

<project name="Trying to delete" default="test" basedir="." xmlns:sf="antlib:com.salesforce">

<property file="build.properties"/>
<property environment="env"/>

<!-- Setting default value for username, password and session id properties to empty string 
     so unset values are treated as empty. Without this, ant expressions such as ${sf.username}
     will be treated literally.
-->
<condition property="sf.username" value=""> <not> <isset property="sf.username"/> </not> </condition>
<condition property="sf.password" value=""> <not> <isset property="sf.password"/> </not> </condition>
<condition property="sf.sessionId" value=""> <not> <isset property="sf.sessionId"/> </not> </condition>

<setproxy proxyHost="${proxy.host}" proxyPort="${proxy.port}"/>

<taskdef resource="com/salesforce/antlib.xml" uri="antlib:com.salesforce">
    <classpath>
        <pathelement location="ant-salesforce.jar" />           
    </classpath>
</taskdef>

<!-- Shows removing code; only succeeds if done after deployCode -->
<target name="removecodepkg">
  <sf:deploy username="${sf.username}" password="${sf.password}" sessionId="${sf.sessionId}" serverurl="${sf.serverurl}" maxPoll="${sf.maxPoll}" deployRoot="removecodepkg"/>
</target>

%ROOT%/ant-migration-tool/removecodepkg/destructiveChanges.xml

    <?xml version="1.0" encoding="UTF-8"?>
<Package xmlns="http://soap.sforce.com/2006/04/metadata">
    <fullName>codepkg</fullName>
    <types>
        <members>ClassIWantToDelete</members>
        <members>TestClassForClassIWantToDelete</members>
        <name>ApexClass</name>
    </types>
    <types>
        <members>InactiveTriggerIWantToDelete</members>
        <members>AnotherInactiveTriggerIWantToDelete</members>
        <name>ApexTrigger</name>
    </types>
    <version>53.0</version>
</Package>

%ROOT%/ant-migration-tool/removecodepkg/package.xml

    <?xml version="1.0" encoding="UTF-8"?>
<Package xmlns="http://soap.sforce.com/2006/04/metadata">
    <fullName>codepkg</fullName>
    <types>
        <members>ClassIWantToDelete</members>
        <members>TestClassForClassIWantToDelete</members>
        <name>ApexClass</name>
    </types>
    <types>
        <members>InactiveTriggerIWantToDelete</members>
        <members>AnotherInactiveTriggerIWantToDelete</members>
        <name>ApexTrigger</name>
    </types>
    <version>53.0</version>
</Package>

This is what I get from ant -v removecodepkg

%ROOT%\ant-migration-tool\build.xml:24: Failed to login: Failed to send request to https://login.salesforce.com/services/Soap/u/54.0

Total time: 1 second
PS %ROOT%\ant-migration-tool> ant -v removecodepkg
Apache Ant(TM) version 1.10.12 compiled on October 13 2021
Trying the default build file: build.xml
Buildfile: %ROOT%\ant-migration-tool\build.xml
Detected Java version: 11 in: C:\Program Files\Zulu\zulu-11
Detected OS: Windows 10
parsing buildfile %ROOT%\ant-migration-tool\build.xml with URI = file:/%ROOT%/ant-migration-tool/build.xml
Project base dir set to: %ROOT%\ant-migration-tool
parsing buildfile jar:file:/C:/apache-ant-1.10.12/lib/ant.jar!/org/apache/tools/ant/antlib.xml with URI = jar:file:/C:/apache-ant-1.10.12/lib/ant.jar!/org/apache/tools/ant/antlib.xml from a zip file
 [property] Loading %ROOT%\ant-migration-tool\build.properties
 [property] Loading Environment env.
 [setproxy] Setting proxy to proxy :8080
parsing buildfile jar:file:/%ROOT%/ant-migration-tool/ant-salesforce.jar!/com/salesforce/antlib.xml with URI = jar:file:/%ROOT%/ant-migration-tool/ant-salesforce.jar!/com/salesforce/antlib.xml from a zip file
Build sequence for target(s) `removecodepkg' is [removecodepkg]
Complete build sequence is [removecodepkg, ]

removecodepkg:
[antlib:com.salesforce] Could not load definitions from resource com/salesforce/antlib.xml. It could not be found.
[sf:deploy] Using proxy: proxy :8080
[sf:deploy] Note: use ant -verbose to get more information on the failure

BUILD FAILED
%ROOT%\ant-migration-tool\build.xml:24: Failed to login: Failed to send request to https://login.salesforce.com/services/Soap/u/54.0
        at com.salesforce.ant.SFDCAntTask.doLogin(SFDCAntTask.java:237)
        at com.salesforce.ant.SFDCAntTask.getMetadataConnection(SFDCAntTask.java:266)
        at com.salesforce.ant.SFDCMDAPIAntTaskRunner.runTask(SFDCMDAPIAntTaskRunner.java:20)
        at com.salesforce.ant.DeployTask.execute(DeployTask.java:63)
        at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:299)
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
        at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.base/java.lang.reflect.Method.invoke(Method.java:566)
        at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:99)
        at org.apache.tools.ant.Task.perform(Task.java:350)
        at org.apache.tools.ant.Target.execute(Target.java:449)
        at org.apache.tools.ant.Target.performTasks(Target.java:470)
        at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1401)
        at org.apache.tools.ant.Project.executeTarget(Project.java:1374)
        at org.apache.tools.ant.helper.DefaultExecutor.executeTargets(DefaultExecutor.java:41)
        at org.apache.tools.ant.Project.executeTargets(Project.java:1264)
        at org.apache.tools.ant.Main.runBuild(Main.java:818)
        at org.apache.tools.ant.Main.startAnt(Main.java:223)
        at org.apache.tools.ant.launch.Launcher.run(Launcher.java:284)
        at org.apache.tools.ant.launch.Launcher.main(Launcher.java:101)
Caused by: com.sforce.ws.ConnectionException: Failed to send request to https://login.salesforce.com/services/Soap/u/54.0
        at com.sforce.ws.transport.SoapConnection.send(SoapConnection.java:128)
        at com.sforce.soap.partner.PartnerConnection.login(PartnerConnection.java:845)
        at com.salesforce.ant.SFDCAntTask.doLogin(SFDCAntTask.java:230)
        ... 20 more
Caused by: java.net.UnknownHostException: proxy
        at java.base/java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:220)
        at java.base/java.net.Socket.connect(Socket.java:609)
        at java.base/java.net.Socket.connect(Socket.java:558)
        at java.base/sun.net.NetworkClient.doConnect(NetworkClient.java:182)
        at java.base/sun.net.www.http.HttpClient.openServer(HttpClient.java:474)
        at java.base/sun.net.www.http.HttpClient$1.run(HttpClient.java:526)
        at java.base/sun.net.www.http.HttpClient$1.run(HttpClient.java:524)
        at java.base/java.security.AccessController.doPrivileged(Native Method)
        at java.base/sun.net.www.http.HttpClient.privilegedOpenServer(HttpClient.java:523)
        at java.base/sun.net.www.http.HttpClient.openServer(HttpClient.java:564)
        at java.base/sun.net.www.protocol.https.HttpsClient.<init>(HttpsClient.java:265)
        at java.base/sun.net.www.protocol.https.HttpsClient.New(HttpsClient.java:372)
        at java.base/sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.getNewHttpClient(AbstractDelegateHttpsURLConnection.java:191)
        at java.base/sun.net.www.protocol.http.HttpURLConnection.plainConnect0(HttpURLConnection.java:1227)
        at java.base/sun.net.www.protocol.http.HttpURLConnection.plainConnect(HttpURLConnection.java:1081)
        at java.base/sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.connect(AbstractDelegateHttpsURLConnection.java:177)
        at java.base/sun.net.www.protocol.http.HttpURLConnection.getOutputStream0(HttpURLConnection.java:1362)
        at java.base/sun.net.www.protocol.http.HttpURLConnection.getOutputStream(HttpURLConnection.java:1337)
        at java.base/sun.net.www.protocol.https.HttpsURLConnectionImpl.getOutputStream(HttpsURLConnectionImpl.java:246)
        at com.sforce.ws.transport.JdkHttpTransport.connectRaw(JdkHttpTransport.java:143)
        at com.sforce.ws.transport.JdkHttpTransport.connectLocal(JdkHttpTransport.java:103)
        at com.sforce.ws.transport.JdkHttpTransport.connectLocal(JdkHttpTransport.java:98)
        at com.sforce.ws.transport.JdkHttpTransport.connect(JdkHttpTransport.java:94)
        at com.sforce.ws.transport.SoapConnection.send(SoapConnection.java:104)
        ... 22 more

Total time: 1 second
2
  • I have a feeling that there is a confusion between Security Token and SessionId. Generally speaking, sf ant will exchange username and password (password + security token) for valid session, therefore you need to specify either username + password or session. Try to remove it to see if it helps.
    – kurunve
    Commented Jul 8, 2022 at 22:05
  • That's helpful. Thank you!
    – d-fws
    Commented Jul 18, 2022 at 21:59

1 Answer 1

0

It may be due to your package.xml. Your package package.xml should be empty as below. As per the Salesforce documentation "To deploy the destructive changes, you must also have a package.xml file that lists no components to deploy, includes the API version, and is in the same directory as destructiveChanges.xml:"

Also you can set testLevel="RunSpecifiedTests" and keep only one existing test class in <runTest>TestClass1</runTest> to make the process faster.

package.xml

<?xml version="1.0" encoding="UTF-8"?>
<Package xmlns="http://soap.sforce.com/2006/04/metadata">
    <version>55.0</version>
</Package>

You must log in to answer this question.

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