I have a bulk set of records coming in as input to my API which need to be upserted. The way I am upserting them is as follows.
- Retrieve all records considering account Ids ( records have master look up on Account object)
- Construct primary keys using few fields of the records as the client sending request is not aware of Ids of records and have them in a map.
- Now, I iterate across the request records sent to the API, build the key and get its value from the above built map. If present, I update else I create a new record.
This works to update on single records only but not on all records satisfying the primary key built upon. Come what may, there could always be duplicate keys because we are not using IDs and can't use as well because they are not present in the client request.
Could someone guide me in this case to fix the design to update all records and not just one record in map. Cant we have a structure which will store all the records with same keys. Any help would be greatly appreciated!