{"record":{"id":"848c34201d24f060","repo":"pentaho/pentaho-kettle","slug":"salesforceupsert-failedinwrite","errorCode":null,"errorMessage":"SalesforceUpsert.FailedInWrite","messagePattern":"SalesforceUpsert\\.FailedInWrite","errorType":"exception","errorClass":"KettleException","httpStatus":null,"severity":"error","filePath":"plugins/salesforce/core/src/main/java/org/pentaho/di/trans/steps/salesforceupsert/SalesforceUpsert.java","lineNumber":179,"sourceCode":"          // Set Null to fields\n          sobjPass.setFieldsToNull( fieldsToNull.toArray( new String[fieldsToNull.size()] ) );\n        }\n        // Load the buffer array\n        data.sfBuffer[data.iBufferPos] = sobjPass;\n        data.outputBuffer[data.iBufferPos] = rowData;\n        data.iBufferPos++;\n      }\n\n      if ( data.iBufferPos >= meta.getBatchSizeInt() ) {\n        if ( log.isDetailed() ) {\n          logDetailed( \"Calling flush buffer from writeToSalesForce\" );\n        }\n        flushBuffers();\n      }\n    } catch ( KettleException ke ) {\n      throw ke;\n    } catch ( Exception e ) {\n      throw new KettleException( BaseMessages.getString( PKG, \"SalesforceUpsert.FailedInWrite\", e.toString() ) );\n    }\n  }\n\n  void setFieldInSObject( SObject sobjPass, XmlObject element ) {\n    Iterator<XmlObject> children = element.getChildren();\n    String name = element.getName().getLocalPart();\n    if ( !children.hasNext() ) {\n      sobjPass.setSObjectField( name, element.getValue() );\n    } else {\n      SObject child = new SObject();\n      child.setName( new QName( name ) );\n      while ( children.hasNext() ) {\n        setFieldInSObject( child, children.next() );\n      }\n      sobjPass.setSObjectField( name, child );\n    }\n  }\n","sourceCodeStart":161,"sourceCodeEnd":197,"githubUrl":"https://github.com/pentaho/pentaho-kettle/blob/f3058517a153da500bf4551f46d79b91bf8ec552/plugins/salesforce/core/src/main/java/org/pentaho/di/trans/steps/salesforceupsert/SalesforceUpsert.java#L161-L197","documentation":"Thrown in SalesforceUpsert.writeToSalesForce when an unexpected (non-Kettle) exception escapes the buffer/flush logic. Unlike KettleExceptions (rethrown as-is), generic Exceptions are wrapped with this message containing e.toString(). It usually means the write to Salesforce failed in an unforeseen way.","triggerScenarios":"Any RuntimeException or checked non-Kettle exception while building SObjects or flushing buffers — e.g. NullPointerException when a mapped stream field value is null for an external-ID field, class-cast issues, or SOAP client faults.","commonSituations":"Null values in fields mapped to Salesforce external IDs; type conversions between Kettle values and SObject fields; Salesforce WSC library errors; unexpected nulls in upsert key columns.","solutions":["Read e.toString() in the message to identify the wrapped root exception.","Check for null values in fields mapped as external IDs — set them to empty-safe defaults or filter those rows first.","Validate that stream field data types match the target Salesforce field types (string vs number vs date).","Enable error handling on the step to divert failing rows and inspect them."],"exampleFix":"// before: null external-id value causes NPE downstream\nif (row[fieldNr] == null) throw new KettleException(\"null ext id\");\n// after: substitute a safe value before the upsert step\n// Use 'If field value is null' / NVL: NVL(externalIdField, \"MISSING_ID\")","handlingStrategy":"validation","validationCode":"for (String extIdField : meta.getUpdateStream()) {\n  int idx = inputRowMeta.indexOfValue(extIdField);\n  if (idx >= 0 && rowData[idx] == null) {\n    throw new KettleException(\"Null value in external-ID mapped field: \" + extIdField);\n  }\n}","typeGuard":null,"tryCatchPattern":"try { writeToSalesForce(rowData); } catch (KettleException e) { if (!e.getMessage().contains(\"FailedInWrite\")) throw e; log.error(\"Wrapped write failure: \" + e.getMessage()); sendRowToErrorStream(rowData, e); }","preventionTips":["Replace nulls in external-ID columns with NVL before the step","Validate field data types against Salesforce field types","Enable step error handling to capture failing rows"],"tags":["pentaho","kettle","salesforce","upsert","unexpected-exception"],"backgroundTag":"unexpected-response-shape","analyzedSha":"f3058517a153da500bf4551f46d79b91bf8ec552","analyzedAt":"2026-09-13T14:04:16.340Z","contentChangedAt":"2026-09-13T14:04:16.340Z","schemaVersion":2},"datasetVersion":"2026-09-20T23:17:15.980Z"}