Save new entry in Database - Issue

I’ve built an Android app, and I have a database on backendless. Now I want to add a new entry from my Android app directly to that same database. This is how my code looks like:

    override suspend fun submitColorPalette(colorPalette: ColorPalette): ColorPalette {
        return suspendCoroutine { continuation ->
            backendless.of(ColorPalette::class.java).save(
                colorPalette,
                object : AsyncCallback<ColorPalette> {
                    override fun handleResponse(response: ColorPalette) {
                        Log.d("BackendlessDataSource", response.colors)
                        continuation.resume(response)
                    }

                    override fun handleFault(fault: BackendlessFault?) {
                        Log.d("BackendlessDataSource", "${fault?.message}")
                        Log.d("BackendlessDataSource", "${fault?.extendedData}")
                        Log.d("BackendlessDataSource", "${fault?.code}")
                        Log.d("BackendlessDataSource", "${fault?.detail}")
                        continuation.resume(ColorPalette())
                    }
                }
            )
        }
    }

I’m using ‘save’ function, and I’m passing ColorPalette object to it, which contains only two fields actually: approved(Boolean), colors(String). I haven’t included any other fields from that ColorPalette database that I already have, because I guess that other values like objectId, ownerId are automatically populated? And other fields that I don’t pass directly can be empty?

Nevertheless, when I try to submit that object that contains those two values, I get this message as a response: “Entity with ID not found”. Error Code: 1000

Here’s my database schema btw.

Hi @Stefan_Jovanovic

I guess that other values like objectId, ownerId are automatically populated? And other fields that I don’t pass directly can be empty?

Yes, you are correct. Fields for which you do not provide values should contain nulls as a values otherwise they will be considered to be populated.

Talking about your error. Is objectId field in passed entity contains null? If it contains some value ( even empty string ) save will try to perform update instead of create.

Regards, Andriy

1 Like

Oh great, I’ve added their default value to be null. Works now.