How to get the data which are not successfully inserted in database?

I am inserting multiple records of cdt type to database in writetodatabaseentity() function. I want to get those records which are not successfully added to database. How to achive this?

  Discussion posts and replies are publicly visible

Parents
  • 0
    Certified Lead Developer
    HI

    Do you want to say, when you are persisting an array of CDT to the database using smart service function, only few rows are being inserted and rest all are getting fail? Are you facing this issue? If so, did you try inspecting the error root cause?

    And if so, then following points you should consider here:

    1. Here difference will not able able to help you, because before persisting the data, your Primary Key values will be null but after persisting, each successfully persisted row will hold their Primary Key Value, means it's not the same, and every single row will be treated as different (irrespective of whether that row was successfully persisted or not).

    2. You need to manually check the error root cause (e.g. some fields are marked as Not Null but you are trying to push null values for those fields in few of the indexes of this CDT || your content exceeding the max number of character limit etc..) and then you need to perform some sort of validation for making sure that the content is not exceeding the max character count. Also either alter the column to nullable else make sure, a column shouldn't hold Empty values and other additional checks (if any).

    As per my understanding, this is something you need to take care before persisting the data into the database. So that we can avoid the partial failure.

    Hope this will help you in analysing & debugging this issue.
Reply
  • 0
    Certified Lead Developer
    HI

    Do you want to say, when you are persisting an array of CDT to the database using smart service function, only few rows are being inserted and rest all are getting fail? Are you facing this issue? If so, did you try inspecting the error root cause?

    And if so, then following points you should consider here:

    1. Here difference will not able able to help you, because before persisting the data, your Primary Key values will be null but after persisting, each successfully persisted row will hold their Primary Key Value, means it's not the same, and every single row will be treated as different (irrespective of whether that row was successfully persisted or not).

    2. You need to manually check the error root cause (e.g. some fields are marked as Not Null but you are trying to push null values for those fields in few of the indexes of this CDT || your content exceeding the max number of character limit etc..) and then you need to perform some sort of validation for making sure that the content is not exceeding the max character count. Also either alter the column to nullable else make sure, a column shouldn't hold Empty values and other additional checks (if any).

    As per my understanding, this is something you need to take care before persisting the data into the database. So that we can avoid the partial failure.

    Hope this will help you in analysing & debugging this issue.
Children