0
votes

Im trying to map data from database to salesforce in mule is using CreateBulk option in Salesforce Connector -->

<flow name="datamapperFlow1" doc:name="datamapperFlow1">
    <poll doc:name="Poll">
        <fixed-frequency-scheduler frequency="30" timeUnit="SECONDS"/>
        <db:select config-ref="Generic_Database_Configuration" doc:name="Database">
            <db:parameterized-query><![CDATA[select * from Persons1]]></db:parameterized-query>
        </db:select>
    </poll>
    <logger message="#[payload]" level="INFO" doc:name="Logger"/>
    <foreach doc:name="For Each">
        <data-mapper:transform config-ref="Map_To_HRISASI__c" doc:name="Map To HRISASI__c"/>
    </foreach>
    <sfdc:create-bulk config-ref="Salesforce" type="HRISASI__c" doc:name="Salesforce">
        <sfdc:objects ref="#[payload]"/>
    </sfdc:create-bulk>
    <logger message="#[payload]" level="INFO" doc:name="Logger"/>
</flow>

A batch job is created but records are failed to insert with the below error in sales force

<result>
<errors>
<fields>PHONE</fields>
<fields>EMPNAME</fields>
<fields>EMPLOYEEID</fields>
<message>
HRISASI__c: bad field names on insert/update call: PHONE, EMPNAME, EMPLOYEEID
</message>
<statusCode>INVALID_FIELD_FOR_INSERT_UPDATE</statusCode>
</errors>
<success>false</success>
<created>false</created>
</result>

my Data Mapper script looks like the below

//MEL
//START -> DO NOT REMOVE
output.__id = input.__id;
//END -> DO NOT REMOVE
output.EmployeeId__c = input.EmpId;
output.EmpName__c = input.Empname;
output.Phone__c = input.Phone;

Could someone please tell me what is the reason for the error

Thankyou in advance

1

1 Answers

0
votes

The problem was because of using the datamapper inside the for each. Payload outside the foreach doesn't contains the mapping and hence error was thrown when trying to map the data to salesforce