Learning this rocked my world. It’s been a frustration when importing or synchronizing records between my legacy system and NetSuite. If I submit a request to create or update a record in NetSuite and all the references to related records are not present, I get a missing RecordRef error and the entire operation fails. In order to beat this, I preceded my insert/update operations with queries to ascertain the state of each reference. From a performance perspective, this was expensive.
So here’s how to improve the performance of your insert/update transactions by skipping all the reference checks.
- Create a new List<Entity or Transaction Type>.
List<CustomRecord> custRecList = new List<CustomRecord>(); - Create a new [Entity or Transaction type] object.
CustomRecord custRec = new CustomRecord(
recType = new RecordRef() {
internalid = “9999” // Key to my custom record type
}
, externalId = “xxxxxxxx” // An actual record Key
, customFieldList = CustomFieldRef[] {}
); - Add fields that you know will NOT blow up on missing RecordRefs.
- ExternalId
- Name
- And create a customFieldList array and populate the “safe” fields.
- Add custRec to CustRecList.
custRecList.Add(custRec) - NOW… HERE IS THE SECRET SAUCE… DON’T MISS IT.
Recreate custRec with a record key (externalId) that references the record you just pushed onto the list in step 4. Then add one field that you suspect might have a missing RecordRef. And push that new object onto the list.
CustomRecord custRec = new CustomRecord(
recType = new RecordRef() {
internalid = “9999”
}
, externalId = “xxxxxxxx”
//, body field that might fail because of a missing RecordRef
, customFieldList = CustomFieldRef[] {
// custom field that might fail because of a missing RecordRef
}
); - And finally, submit the entire list as your insert/update/upsert.
netSuiteService.upsertList(custRecList) - As you check the results, you’ll find that the initial insert/update request succeeds. Subsequent requests, where you have a missing RecordRef will fail. But that’s OK. It’s expected!
I hope this is as great a revelation to you as it was to me. Happy coding!