0
votes

I am having a problem uploading metadata to a Salesforce managed app build org, via the ant migration tool. The original problem was in quite a major app, but I have been able to cut it down to 2 files, which demonstrate the issue: a Platform Event and an Apex class (web service) that publishes it.

objects/CTIDeviceUpdateEvent__e:

<?xml version="1.0" encoding="UTF-8"?>
<CustomObject xmlns="http://soap.sforce.com/2006/04/metadata">
    <deploymentStatus>Deployed</deploymentStatus>
    <description>Event raised by AVS when the CTI user updates their outbound device.</description>
    <eventType>StandardVolume</eventType>
    <fields>
        <fullName>NewCtiDevice__c</fullName>
        <externalId>false</externalId>
        <isFilteringDisabled>false</isFilteringDisabled>
        <isNameField>false</isNameField>
        <isSortingDisabled>false</isSortingDisabled>
        <label>NewCtiDevice</label>
        <length>64</length>
        <required>true</required>
        <type>Text</type>
        <unique>false</unique>
    </fields>
    <fields>
        <fullName>UserId__c</fullName>
        <externalId>false</externalId>
        <isFilteringDisabled>false</isFilteringDisabled>
        <isNameField>false</isNameField>
        <isSortingDisabled>false</isSortingDisabled>
        <label>UserId</label>
        <precision>18</precision>
        <required>true</required>
        <scale>0</scale>
        <type>Number</type>
        <unique>false</unique>
    </fields>
    <label>CTI Device Update Event</label>
    <pluralLabel>CTI Device Update Events</pluralLabel>
</CustomObject>

classes CtiDeviceUpdateWebService.cls

global with sharing class CtiDeviceUpdateWebService {

    webservice static void ctiDeviceUpdate(Integer natterboxUserId, String newCtiDeviceRaw) {

        List<CTIDeviceUpdateEvent__e> evlist = new List<CTIDeviceUpdateEvent__e> { new CTIDeviceUpdateEvent__e(UserId__c = 1, NewCTIDevice__c = '2001') } ;

        // Call method to publish events
        List<Database.SaveResult> results = EventBus.publish(evlist);

        // Inspect publishing result for each event
        for (Database.SaveResult sr : results) {
            if (sr.isSuccess()) {
                System.debug('Successfully published event.');
            } else {
                for(Database.Error err : sr.getErrors()) {
                    System.debug('Error returned: ' +
                            err.getStatusCode() +
                            ' - ' +
                            err.getMessage());
                }
            }
        }
    }
}

package.xml:

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

I get the following result from the metadata API when I deploy it:

[sf:deploy] Request for a deploy submitted successfully.
[sf:deploy] Request ID for the current deploy task: 0Af1n00001VmcmHCAR
[sf:deploy] Waiting for server to finish processing the request...
[sf:deploy] Request Status: InProgress
[sf:deploy] Request Status: Failed

BUILD FAILED
/Users/jim.page/Documents/salesforce_ant_43.0/nbavs/build.xml:31: 
*********** DEPLOYMENT FAILED ***********
Request ID: 0Af1n00001VmcmHCAR

All Component Failures:
1.  classes/CtiDeviceUpdateWebService.cls -- Error: Method does not exist or incorrect signature: void publish(List<CTIDeviceUpdateEvent__e>) from the type EventBus (line 12, column 54)
2.  classes/CtiDeviceUpdateWebService.cls -- Error: Invalid type: CTIDeviceUpdateEvent__e (line 9, column 9)

*********** DEPLOYMENT FAILED ***********

I have tried different API versions, different settings in the event metadata of various kinds, using my managed package's namespace, and google and I are out of ideas.

Note - when I just deploy the platform event on its own, the deployment works and I can see it under Setup|Platform Events in the build org. But when the web service is added into the mix, the deployment fails. There is no problem accessing Custom Objects from the web service.

Note also that this code works fine in a dev org.

1

1 Answers

1
votes

Ok - the moment I posted this question, one of my colleagues gave me the answer. The class metadata file had a version number that was pre-41.0 when platform events went into production.