2

I'm trying to read a set of records from a custom Big Object, update a long text field (not part of the object index), and then upsert back. When trying to update the value of the field I get 'Field is not writable'. All fields have update permissions for my running user and I'm able to insert brand new records fine, its just trying to update the field that throws this error. Is there an undocumented limitation or am I doing something fundamentally wrong?

List<myObject__b> mo= [SELECT longtextfield__c FROM myObject__b LIMIT 1];
for(myObject__b o : mo){
    o.longtextfield__c = 'new value'; //throws a not writable error
}
database.insertImmediate(mo);
1
  • 2
    Can you check the Field Level Security of longtextfield__c is not Read only? Feb 18, 2019 at 18:30

2 Answers 2

2

I believe the issue is related to running two insert operations in the same namespace before the record has been committed.

e.g., This will not work:

public class TESTBigObject  {

    public TESTBigObject(){
        Datetime timestamp = DateTime.newInstance(1997, 1, 31, 7, 8, 16); //Datetime.now();

        eOrderLog__b log = new eOrderLog__b();
        log.Order_Number__c = '98398-ABC'; // Index
        log.TimeStamp__c = timestamp; //Index
        log.status__c = 'PROCESSING';
        database.insertImmediate(log);

        // UPDATE STATUS - Fails with Field is not writable
        log.JSON_Request__c = 'TEST 123';
        log.Order_Number__c = '98398-ABC';
        log.TimeStamp__c = timestamp;
        log.status__c = 'FINISHED';
        database.insertImmediate(log);
    }
}

If you execute the following twice you get the desired behavior (Update of Status)

public class TESTBigObject  {

    public TESTBigObject(){
        Datetime timestamp = DateTime.newInstance(1997, 1, 31, 7, 8, 16); //Datetime.now();

        eOrderLog__b log = new eOrderLog__b();
        log.Order_Number__c = '98398-ABC'; // Index
        log.TimeStamp__c = timestamp; //Index
        log.status__c = 'PROCESSING'; // CHANGE to FINISHED before executing again.
        database.insertImmediate(log);
    }
}

The way to work around this use the Queueable interface. See example here.

1
  • +1 how you stumbled upon this? Is this documented somewhere? Feb 21, 2019 at 20:08
0

I know has been a lot since this error but I had the same problem recently and I solved like this, maybe this help to someone:

List<myObject__b> toUpdateBO = new List<myObject__b>();
List<myObject__b> mo= [SELECT Index__c FROM myObject__b];
for(myObject__b o : mo){
    // Define the new record with the same index
    myObject__b newO = new myObject__b(Index__c= o.Index__c);
    newO.textfield__c = 'new value'; //not required to query it
    toUpdateBO.add(newO);
}
database.insertImmediate(toUpdateBO);

Information in the Big Objects Implementation Guide

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .