4

I am trying to restore a custom object from my backup where I am trying to upsert the records. Following this example. The external field is Id here. Assuming that there are no records matching, the CSV that uploaded contains Id fields. When I try to run the batch job, all the records that are received have the error message:

ENTITY_IS_DELETED:entity is deleted:--

Copy pasting where upsert would fail:

How Upsert Chooses to update() or create()

Upsert uses the external ID to determine whether it should create a new record or update an existing one:

If the external ID is not matched, then a new record is created.
If the external ID is matched once, then the existing record is updated.
If the external ID is matched multiple times, then an error is reported.
When batch updating multiple records where the external ID is the same for two or more records in your batch call, those records will be

marked as errors in the UpsertResult file. The records will be neither created or updated.

The object contained no records and why does upsert fail where the expected operation is to create a new record? I understand that the upsert will create new ids, in case of upsert. In that case, will I be able to build a mapping with the old as well as new record ids?

EDIT:

The requirement is that a salesforce object exists and upsert the existing records that are in my backup to salesforce.

The external field id is the id of this object and not it's external field id.

I aggregated the records in the form of a CSV, tried upsert operations. It failed with the errors above. However, when the operation type is changed to insert. The records are inserted successfully. Doesn't upsert handle this scenario? Should I manually check for the presence of each record while inserting and then change the operation type accordingly (probably would have to resort to SOAP for this case)?

  • 1
    Are the records in a deleted status? Check your recycle bin. – Jesse Milburn Mar 31 '16 at 16:54
  • There are no records for the object. The scenario is to upsert the records regardless of their presence; if present update else create. – dmachop Mar 31 '16 at 17:42
  • 1
    That doesn't mean there weren't ever records for the object, which is what I was asking. If the records were there at some point and the were soft deleted, then they are still in the org recycle bin. – Jesse Milburn Mar 31 '16 at 19:06
  • @JesseMilburn The records that I tried to upsert never existed in Salesforce. I wanted to know whether upsert is the right call for this since my record list consists of records that may or may not exist for the object in Salesforce. – dmachop Mar 31 '16 at 19:31
  • @dmachop Just checking, but does the CSV that came for the backup still have the original 15/18 character Salesforce ID for the records that are being restored? Ideally these wouldn't be in the CSV at they would take precedence over the External ID field specified. – Daniel Ballinger Apr 6 '16 at 22:48

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.