function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Rocio VivancoRocio Vivanco 

INVALID_FIELD_FOR_INSERT_UPDATE Error message: Unable to create/update fields: Name

Hi all,

I am struggling since hours trying to find out what the root cause is and how to solve it, but til now without success.

I am trying to deploy a test class.
Here the following relationship: Account has a master detail relationship with Admissions (Admisiones), Study Interests (Intenciones de Estudio), Enrollments (Matriculaciones), Pre-enrollments (Preinscripciones) and Actas.

When trying to deploy the test class, I am getting these errors:
 
EnvioDeCorreoTest	ActaTest	System.DmlException: Insert failed. First exception on row 0; first error: INVALID_FIELD_FOR_INSERT_UPDATE, Unable to create/update fields: Name. Please check the security settings of this field and verify that it is read/write for your profile or permission set.: [Name]
Stack Trace: Class.EnvioDeCorreoTest.InsertAccount: line 12, column 1 Class.EnvioDeCorreoTest.ActaTest: line 146, column 1

EnvioDeCorreoTest	Admisiontest	System.DmlException: Insert failed. First exception on row 0; first error: INVALID_FIELD_FOR_INSERT_UPDATE, Unable to create/update fields: Name. Please check the security settings of this field and verify that it is read/write for your profile or permission set.: [Name]
Stack Trace: Class.EnvioDeCorreoTest.InsertAccount: line 12, column 1 Class.EnvioDeCorreoTest.Admisiontest: line 36, column 1

EnvioDeCorreoTest	Intencionesestudiotest	System.DmlException: Insert failed. First exception on row 0; first error: INVALID_FIELD_FOR_INSERT_UPDATE, Unable to create/update fields: Name. Please check the security settings of this field and verify that it is read/write for your profile or permission set.: [Name]
Stack Trace: Class.EnvioDeCorreoTest.InsertAccount: line 12, column 1 Class.EnvioDeCorreoTest.Intencionesestudiotest: line 54, column 1

EnvioDeCorreoTest	Matriculaciontest	System.DmlException: Insert failed. First exception on row 0; first error: INVALID_FIELD_FOR_INSERT_UPDATE, Unable to create/update fields: Name. Please check the security settings of this field and verify that it is read/write for your profile or permission set.: [Name]
Stack Trace: Class.EnvioDeCorreoTest.InsertAccount: line 12, column 1 Class.EnvioDeCorreoTest.Matriculaciontest: line 98, column 1

EnvioDeCorreoTest	Preinscripciontest	System.DmlException: Insert failed. First exception on row 0; first error: INVALID_FIELD_FOR_INSERT_UPDATE, Unable to create/update fields: Name. Please check the security settings of this field and verify that it is read/write for your profile or permission set.: [Name]
Stack Trace: Class.EnvioDeCorreoTest.InsertAccount: line 12, column 1 Class.EnvioDeCorreoTest.Preinscripciontest: line 73, column 1

EnvioDeCorreoTest	Titulotest	System.DmlException: Insert failed. First exception on row 0; first error: INVALID_FIELD_FOR_INSERT_UPDATE, Unable to create/update fields: Name. Please check the security settings of this field and verify that it is read/write for your profile or permission set.: [Name]
Stack Trace: Class.EnvioDeCorreoTest.InsertAccount: line 12, column 1 Class.EnvioDeCorreoTest.Titulotest: line 122, column 1
My code has the following Method:
 
public static void InsertAccount() {

        Id recordTypeId = Schema.SObjectType.Account.getRecordTypeInfosByName().get('Alumnos').getRecordTypeId();
        account = new Account(Name = 'Test Account', PersonEmail = 'testaccount@test.com', Nacionalidad__c = 'España', Tipo_de_Id__c = 'DNI', DNI__c = '12345678', RecordTypeId = recordTypeId);
        insert account;
        
   }
What it does is to insert a new account with record type "Alumnos" (Students).

My test class EnviodeCorreoTest looks like this:
 
@isTest(SeeAllData=true)
private class EnvioDeCorreoTest {

    static Preinscripci_n__c preinscripcion;
    static Product2 postgrado;
    static Account account;

   public static void InsertAccount() {

        Id recordTypeId = Schema.SObjectType.Account.getRecordTypeInfosByName().get('Alumnos').getRecordTypeId();
        account = new Account(Name = 'Test Account', PersonEmail = 'testaccount@test.com', Nacionalidad__c = 'España', Tipo_de_Id__c = 'DNI', DNI__c = '12345678', RecordTypeId = recordTypeId);
        insert account;
        
   }
   
 @isTest 
    static void Admisiontest() {
        
        InsertAccount();
        InsertPostgrado();
        InsertContacto();
        Admisi_n__c admision = new Admisi_n__c();
        admision.Nombre_de_la_cuenta__c = account.Id;
        admision.Idioma_de_preferencia__c = 'Español';
        admision.Programa_Acad_mico__c = postgrado.Id;

        insert admision;
        
        Test.startTest();
        EnvioDeCorreo.enviarCorreoAdmision(admision, 'Notificaci_n_de_registro_de_Admision');
        Test.stopTest();
    }

...
the rest of the methods for enrollments, pre-enrollments, etc. look similar

What I don't understand is, where is the issue. The error is pointing to the field "Name" of the object Account, so far I understand. If I am executing the deployment as Admin, I have access to this field. In the method Admisiontest() I am calling the InsertAccount() method.
All error lines are also pointing to the line:

InsertAccount();

Can please somebody help me to find the answer?. I am stuck in this issue and can not deploy to Production :(.

 
Best Answer chosen by Rocio Vivanco
Rocio VivancoRocio Vivanco
Alex, I could solve my problem! :). I have amended the line:
 
public static void InsertAccount() {

        Id recordTypeId = Schema.SObjectType.Account.getRecordTypeInfosByName().get('Alumnos').getRecordTypeId();
        account = new Account(Name = 'Test Account', PersonEmail = 'testaccount@test.com', Nacionalidad__c = 'España', Tipo_de_Id__c = 'DNI', DNI__c = '12345678', RecordTypeId = recordTypeId);
        insert account;
        
   }

so that it looks now so:
 
public static void InsertAccount() {

        Id recordTypeId = Schema.SObjectType.Account.getRecordTypeInfosByName().get('Alumnos').getRecordTypeId();
        account = new Account(FirstName = 'Test', LastName = 'Test', PersonEmail = 'testaccount@test.com', Nacionalidad__c = 'España', Tipo_de_Id__c = 'DNI', DNI__c = '12345678', RecordTypeId = recordTypeId);
        insert account;
        
   }
It probably says that there is no access to the Name field because if you insert an account you have to first indicate first name and last name for the first time, giving this information the field Name can be filled.
I also removed the part with the InsertContact() in my code according to this thread:

https://salesforce.stackexchange.com/questions/7747/invalid-cross-reference-key-can-not-select-a-person-account-accountid

So, I could then deploy the test class.
Thank so much anyway for your efforts.

All Answers

Alex EzhilarasanAlex Ezhilarasan
Hi Rocio,

This looks strange. Let's try to find the root cause by progressing one step at a time.
Please confirm you have permission by creating test Account record through Developer Console with the same code in Test class.

-Alex
Rocio VivancoRocio Vivanco
Alex, thank you so much for your answer! :).
Actually I am a newbie in deveopment, so how can I test it?, you mean only to try the InsertAccount method?
Rocio VivancoRocio Vivanco
Yes, I have already run the test classes in Sandbox, but I get the same error message as posted here. There are no other hints showing me what else can be the error cause. With my profile is everything ok, I have access to all fields as Admin.
Rocio VivancoRocio Vivanco
Alex, I could solve my problem! :). I have amended the line:
 
public static void InsertAccount() {

        Id recordTypeId = Schema.SObjectType.Account.getRecordTypeInfosByName().get('Alumnos').getRecordTypeId();
        account = new Account(Name = 'Test Account', PersonEmail = 'testaccount@test.com', Nacionalidad__c = 'España', Tipo_de_Id__c = 'DNI', DNI__c = '12345678', RecordTypeId = recordTypeId);
        insert account;
        
   }

so that it looks now so:
 
public static void InsertAccount() {

        Id recordTypeId = Schema.SObjectType.Account.getRecordTypeInfosByName().get('Alumnos').getRecordTypeId();
        account = new Account(FirstName = 'Test', LastName = 'Test', PersonEmail = 'testaccount@test.com', Nacionalidad__c = 'España', Tipo_de_Id__c = 'DNI', DNI__c = '12345678', RecordTypeId = recordTypeId);
        insert account;
        
   }
It probably says that there is no access to the Name field because if you insert an account you have to first indicate first name and last name for the first time, giving this information the field Name can be filled.
I also removed the part with the InsertContact() in my code according to this thread:

https://salesforce.stackexchange.com/questions/7747/invalid-cross-reference-key-can-not-select-a-person-account-accountid

So, I could then deploy the test class.
Thank so much anyway for your efforts.
This was selected as the best answer
Alex EzhilarasanAlex Ezhilarasan
Lol.! How come it is worked in Sandbox though?
RayaPRayaP
Hello, 

Trying to upload frequencies into the Territory Fields tab, via Data Loader.
I'm recieving the following error:

Update Row Failed:
Unable to create/update fields: xR1_Call_Frequency_Proposal__c. Please check the security settings of this field and verify that it is read/write for your profile or permission set.

What is the problem and how to solve it please.

Thanks.
Stamen Nikolov 4Stamen Nikolov 4

Hi all,

I`m struggling with simlar error. I`m not a backend guy and I need some help to resolve my issue.

Doing an UPSERT to Campaign Members for ~55M records. Using Talend. When initially ran the job i got more then 50% success rate and for the failed ones i had few common errors. One of them that I`m trying to overcome is "INVALID_FIELD_FOR_INSERT_UPDATE:Unable to create/update fields: ContactId. Please check the security settings of this field and verify that it is read/write for your profile or permission set.:ContactId --" 
I`m using "ContactId" for the lookup.
 I tried running the job several times trying different things - Deactivating triggers on Account, Campaign, Campaign Members, also tried reducing the batch size. None of these helped.
 

Could anyone give me a hint what should we do to be able to workaround this? Thanks in advance!

anisha kadhiravanaanisha kadhiravana
Hi all,

I am also facing similar error message below: 
INVALID_FIELD_FOR_INSERT_UPDATE, Unable to create/update fields: Product2Id, PricebookEntryId. Please check the security settings of this field and verify that it is read/write for your profile or permission set.: [Product2Id, PricebookEntryId]

I am running the code as System administrator and it has all access permission. Coming across this error in test class ,as relationship dependencies  i have created records for Product, Pricebookentry, Opportunity Line Item. 
Can anyone give me hint where i could be missing and how to workaround ?
Thanks in advance!!
Mark Allsop 1Mark Allsop 1
I know this is old but I'll post. For example, for the SF QuoteLineItem table insert ,you have to first look up the Product2Id.Id and the PricebookEntryId.Id and use those to insert into those fields. So your product and at least a standard pricebook must exist prior to your QuoteLineItem insert or update.

But another example, like for Order table, you can set the Status field to say 'Draft' but you cannot set the StatusCode, as its a picklist and it will be auto filled by the Status field being set.