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);
  • 2
    Can you check the Field Level Security of longtextfield__c is not Read only? – Pranay Jaiswal Feb 18 at 18:30
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 how you stumbled upon this? Is this documented somewhere? – Pranay Jaiswal Feb 21 at 20:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.