0

I'm trying to update a checkbox field through lightning component and AuraEnabled method but,

  1. When attempting to update checkbox field I get error 'invalid field for insert update bad field names on insert/update'

  2. When I debug out the object being returned for update I get :

    (Object__c:{checkbox_field__c=true, id=a2Cx0000000A4FED9})
    

But when I debug out the Object__C.checkbox_field__c from that object I get:

    false

So, why can't I save, and why is this value seemingly being changed to false.

Apex controller:

public class customApexController{

      @AuraEnabled
      public static void saveObjects(List<object__c> objectDataList){
            System.debug('saving objects:');
            System.debug(objectDataList);
            System.debug('object:');
            System.debug(objectDataList[0]);
            System.debug('checkbox_field__c:');
            System.debug(objectDataList[0].checkbox_field__c);
            System.debug('id:');
            System.debug(objectDataList[0].id);
            objectDataList[0].checkbox_field__c = true;
            System.debug(objectDataList[0].checkbox_field__c);
            update objectDataList;
      }

Returns:

  saving objects:
  (Object__c:{checkbox_field__c=true, id=a2Cx0000000A4FED9})
  object:
  Object__c:{checkbox_field__c=true, id=a2Cx0000000A4FED9}
  checkbox_field__c:
  false
  id:
  a2Cx0000000A4FED9
  true

  System.DmlException: Update failed. First exception on row 0 with id a2Cx0000000A4FED9; first error: INVALID_FIELD_FOR_INSERT_UPDATE, Object__c: bad field names on insert/update call: checkbox_field__c: [checkbox_field__c]

The method calling this is sending the objectDataList parameter as an array of objects with the object data like { Id: 'a2Cx0000000A4FED9', checkbox_field__c: true}

1
  • 1
    In order to better assist we need the component code as well as the apex code. for the component markup and js files are needed. Commented Mar 18, 2019 at 13:40

1 Answer 1

0

Fixed it - it was to do with case sensitivity of field names

Looks like if you are passing object as parameter to AuraEnabled method, field names are case sensitive, but if you just reference the field name in the method body not case sensitive.

You must log in to answer this question.

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