You need to sign in to do that
Don't have an account?
Ab
INVALID_CROSS_REFERENCE_KEY error | Lookup or master detail to opportunity
Hello,
I am copying records from one object to another.
On the old object there exisit a lookup(ManagedPackage__Opportunity__c) to opportunity object, and in New object there exisit a Masterdetail(opportunity__c ) to opportunity
x.opportunity__c = c.ManagedPackage__Opportunity__c;
this line gives error when i try to insert like below
de|"common.apex.runtime.impl.DmlExecutionException: Insert failed. First exception on row 0; first error: INVALID_CROSS_REFERENCE_KEY, invalid cross reference id: []"|0x4951b823
I am copying records from one object to another.
On the old object there exisit a lookup(ManagedPackage__Opportunity__c) to opportunity object, and in New object there exisit a Masterdetail(opportunity__c ) to opportunity
x.opportunity__c = c.ManagedPackage__Opportunity__c;
this line gives error when i try to insert like below
de|"common.apex.runtime.impl.DmlExecutionException: Insert failed. First exception on row 0; first error: INVALID_CROSS_REFERENCE_KEY, invalid cross reference id: []"|0x4951b823
If that is the only thing you are inserting into the object, then that may be your issue. Serializing the object like I posted should give you attributes about the object, along with the fields. But without more information, I cannot say what is going on. The error message you are receiving is extremely generic and cannot be diagnosed with a one line example of your code.
My advice would be to run an anonymous block of code to test it out. Manually build a new record of the new object. Call Database.setSavePoint() before the insert and Database.rollback() after the insert if you are testing this in production. If you can manually insert the record in the anonymous block, then add a series of debug statements to print ALL attributes of the record you are inserting to see where your code is diffing. If you are still stuck, we will need more information in order to help you debug this.
All Answers
It looks like it could be because the old record's lookup was blank. Are you ensuring that the lookup field is not null before copying and inserting to the new object?
This error can mean a lot of different things so it would be helpful to add some debug statements for the new record.
Hope that helps
assuming that "x" is the variable of the object you are inserting. Check all the lookup fields for invalid entries.
09:46:35:000 USER_DEBUG "opportunity__c" : "006b0000004m28yAAA"
09:46:35:000 USER_DEBUG "opportunity__c" : "006b0000005TWMmAAO"
09:46:35:000 USER_DEBUG "opportunity__c" : "006b0000005TkYnAAK"
09:46:35:000 USER_DEBUG "opportunity__c" : "006b0000005TkYnAAK"
I have a list which i am updating
If that is the only thing you are inserting into the object, then that may be your issue. Serializing the object like I posted should give you attributes about the object, along with the fields. But without more information, I cannot say what is going on. The error message you are receiving is extremely generic and cannot be diagnosed with a one line example of your code.
My advice would be to run an anonymous block of code to test it out. Manually build a new record of the new object. Call Database.setSavePoint() before the insert and Database.rollback() after the insert if you are testing this in production. If you can manually insert the record in the anonymous block, then add a series of debug statements to print ALL attributes of the record you are inserting to see where your code is diffing. If you are still stuck, we will need more information in order to help you debug this.