当SFTP记录的日期字段为null时,为什么我的记录没有通过Mulesoft升级到Salesforce?

时间:2019-01-15 14:46:00

标签: java salesforce mulesoft

我正在使用Mulesoft将记录从SFTP集成到Salesforce(upsert)。 在SFTP记录中,日期字段(Store_Close_Date__c)有时为空。 这是在Mulesoft中生成Java异常,因此我编辑了config.xml文件以转换字段。

请在下面找到config.xml

<?xml version="1.0" encoding="UTF-8"?>

<mule xmlns:metadata="http://www.mulesoft.org/schema/mule/metadata" xmlns:dw="http://www.mulesoft.org/schema/mule/ee/dw" xmlns:sfdc="http://www.mulesoft.org/schema/mule/sfdc" xmlns:sftp="http://www.mulesoft.org/schema/mule/sftp" xmlns="http://www.mulesoft.org/schema/mule/core" xmlns:doc="http://www.mulesoft.org/schema/mule/documentation"
    xmlns:spring="http://www.springframework.org/schema/beans" 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-current.xsd
http://www.mulesoft.org/schema/mule/sfdc http://www.mulesoft.org/schema/mule/sfdc/current/mule-sfdc.xsd
http://www.mulesoft.org/schema/mule/sftp http://www.mulesoft.org/schema/mule/sftp/current/mule-sftp.xsd
http://www.mulesoft.org/schema/mule/ee/dw http://www.mulesoft.org/schema/mule/ee/dw/current/dw.xsd
http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd">
    <sfdc:config name="UpsertProducts" username="xxxx" password="xxxx" securityToken="xxxx" url="https://xxxx.my.salesforce.com/services/Soap/u/37.0" doc:name="SFTP_Products"/>
    <sftp:connector name="SFTP_Products" validateConnections="true" autoDelete="false" doc:name="SFTP_Products">
            <service-overrides messageReceiver="chalhoub.ChalhoubSftpMessageReceiverProducts"/>
    </sftp:connector>
    <sftp:endpoint exchange-pattern="request-response" host="localhost" port="22" name="SFTP" responseTimeout="10000" doc:name="SFTP"/>
    <sftp:connector name="SFTP_Locations" validateConnections="true" autoDelete="false" doc:name="SFTP_Locations">
            <service-overrides messageReceiver="chalhoub.ChalhoubSftpMessageReceiverLocations"/>
    </sftp:connector>
    <sfdc:config name="UpsertLocations" username="xxxx" password="xxxx" securityToken="xxxx" url="https://xxxx.my.salesforce.com/services/Soap/u/37.0" doc:name="SFTP_Locations"/>
    <flow name="Products">
        <sftp:inbound-endpoint connector-ref="SFTP_Products" host="xxxx" port="xxxx" path="//" user="xxxx" password="xxxx" responseTimeout="60000" autoDelete="false" doc:name="Get Products"/>
        <message-chunk-splitter messageSize="1000000" doc:name="Products Chunk Splitter"/>
        <dw:transform-message doc:name="Products Transform Message" metadata:id="007db759-7ccf-44fd-b053-0a67709fd56b" ><!-- metadata:id="a9bd1fde-189a-40e7-aed1-85652885c03f" -->
            <dw:input-payload mimeType="application/csv"/>
            <dw:set-payload><![CDATA[%dw 1.0
%output application/java
---
payload map ((payload01 , indexOfPayload01) -> {
    Name: payload01.ITEM_DESC,
    Product_Number__c: payload01.ITEM_NUMBER,
    Primary_VPN__c: payload01.PRIMARY_VPN,
    Department_ID__c: payload01.DEPARTMENT_ID,
    Department_Name__c: payload01.DEPARTMENT_NAME,
    Class_ID__c: payload01.CLASS_ID,
    SubClass_ID__c: payload01.SUBCLASS_ID,
    SubClass_Name__c: payload01.SUBCLASS_NAME,
    Department_Brand__c: payload01.DEPARTMENT_BRAND,
    Gender__c: payload01.GENDER,
    Season__c: payload01.SEASON,
    Size__c: payload01.SIZE,
    Color__c: payload01.COLOR,
    Line__c: payload01.LINE,
    Sub_Line__c: payload01."SUB LINE",
    Supplier_Class__c: payload01."SUPPLIER CLASS",
    Supplier_SubClass__c: payload01."SUPPLIER SUBCLASS"
})]]></dw:set-payload>
        </dw:transform-message>
        <sfdc:upsert-bulk config-ref="UpsertProducts" type="Product__c" externalIdFieldName="Product_Number__c" doc:name="Upsert Products ">
            <sfdc:objects ref="#[payload]"/>
        </sfdc:upsert-bulk>
    </flow>
    <flow name="Locations">
        <sftp:inbound-endpoint connector-ref="SFTP_Locations" host="xxxx" port="xxxx" path="//" user="xxxx" password="xxxx" responseTimeout="60000" autoDelete="false" doc:name="Get Locations"/>
        <message-chunk-splitter messageSize="1000000" doc:name="Locations Chunk Splitter"/>
        <dw:transform-message doc:name="Locations Transform Message" metadata:id="a61e8266-246f-4cae-a372-f5fbc641e5c8">
            <dw:input-payload mimeType="application/csv"/>
            <dw:set-payload><![CDATA[%dw 1.0
%output application/java
---
payload map ((payload01 , indexOfPayload01) -> {
    Name: payload01.STORE_NAME,
    Location_Code__c: payload01.STORE,
    Location_Open_Date__c: payload01.STORE_OPEN_DATE as :date{format:"dd.MM.yyyy"}  default 'null',
    Store_Close_Date__c: payload01.STORE_CLOSE_DATE as :date{format:"dd.MM.yyyy"}  default 'null',
    Mall_Name__c: payload01.MALL_NAME,
    Currency_Code__c: payload01.CURRENCY_CODE,
    Country_ID__c: payload01.COUNTRY_ID,
    Country_Description__c: payload01.COUNTRY_DESC,
    Org_Unit_ID__c: payload01.ORG_UNIT_ID,
    Org_Unit_Description__c: payload01.DESCRIPTION
})]]></dw:set-payload>
        </dw:transform-message>
        <sfdc:upsert-bulk config-ref="UpsertLocations" type="Location__c" externalIdFieldName="Location_Code__c" doc:name="Upsert Locations">
            <sfdc:objects ref="#[payload]"/>
        </sfdc:upsert-bulk>
    </flow>


</mule>

现在的问题是,只有不具有Store_Close_Date__c = null的记录才被升级到Salesforce。这可能是我对config.xml文件所做的修改。

所有记录,包括具有Store_Close_Date__c = null的记录,都应加注。

请告知 谢谢

1 个答案:

答案 0 :(得分:0)

此问题是由Dataweave类型转换引起的。

当日期为空时,Dataweave将无法将值转换为日期。

将Dataweave字段映射更改为:

Store_Close_Date__c: (payload01.STORE_CLOSE_DATE as :date{format:"dd.MM.yyyy"}) when payload01.STORE_CLOSE_DATE != null otherwise null

这将确保它首先进行null检查,并且仅在不为null时进行投射

基顿