System.DmlException: Insert failed. First exception on row 0 with id a3hDv0000031GvF; first error: INVALID_FIELD_FOR_INSERT_UPDATE, cannot specify Id in an insert call: [Id]

 

Error :System.DmlException: Insert failed. First exception on row 0 with id a3hDv0000031GvF; first error: INVALID_FIELD_FOR_INSERT_UPDATE, cannot specify Id in an insert call: [Id]

Issue code example :

Validation_Rule_Exception__c settings = Validation_Rule_Exception__c.getOrgDefaults();

        settings.Run_Validation_Rules__c = true;

        Insert settings;

How to fix the issue :

Instead of   "Insert settings" we should use "update settings"; why beacuse in the above code we aren't creating new instance for object that why we should use UPDATE ;

Validation_Rule_Exception__c settings = Validation_Rule_Exception__c.getOrgDefaults();

        settings.Run_Validation_Rules__c = true;

        update settings;

Post a Comment

0 Comments