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
akallioWileyakallioWiley 

Help with Error Handling

I receive the following error when I try to merge 2 contact records: INVALID_FIELD_FOR_INSERT_UPDATE, Contact: bad field names on insert/update call: Comps__r: 

 

The records the I am trying to merge are generated from the following 2 queries:

 

This will give me the childs in the merge...the record that will get deleted:

Contact childCon : [select Id, Acc_No_Part_1__c, Acc_No_Part_2__c, MergeMasterID__c, (select Id, Contact__r.MergeMasterId__c, External_ID__c from Comps__r) from Contact where Id IN :childCons)]

 This gets me the parents:

 

(Contact masterCon : [select Id, Acc_No_Part_1__c, Acc_No_Part_2__c, MergeMasterID__c, (select Id, Contact__c, Contact__r.MergeMasterId__c, External_ID__c from Comps__r) from Contact where Id IN :masterConSet])

 Before I can merge them I have to manipulate the child records found Camps__r. Once those updates are done I run a merge statement.

 

I think the error happens only when the Child Contact does not have any values in Comps__r. My code should be handling that scenario...In other words I use if statements to test if there are records in Comps__r, and if there is isn't then I have code to handle it differently.  

 

When the child contact has records in comps__r then everything works ok. 

 

The other posts that I have found related to this message are not helping, and the definition for the message in docs seems to be way off the mark:

INVALID_FIELD_FOR_INSERT_UPDATE

You can't combine a person account record type change with any other field update.

 

So, I am stumped at this point. 


akallioWileyakallioWiley

I solved this issue by not relying on SOQL parent-to-Child queries. Instead, I built a map: map<Id, List<Comp__c>>

 

which is what my originnal plan was but has held back by another strange error about the selectivity of my query...attributed to the large amount of records in that object. I got help and support to index a field for me and everything seems to be ok now.