0

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.

  1. Retrieve all records considering account Ids ( records have master look up on Account object)
  2. 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.
  3. 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!

  • are you receiving primary keys (or unique key fields or sort of like that) from client? Because UPSERT operation works only on some external id. – Mahmood Dec 16 '14 at 14:45
  • As stated, upsert will only accept a single primary key. Basically, in order to accomplish what you're asking, you would have to query for the existence of records and build your own insert and update sets. The update could accommodate multiple records with the same key if constructed manually like this. – greenstork Dec 16 '14 at 16:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.