11

And no, if you're thinking I'm writing to a formula field, that's not it - read on....

I've been seeing this error sporadically during an upsert on one, and only one, org.

Upsert failed. First exception on row 0 with id a1H00000000VR5lEAG; first error: UNKNOWN_EXCEPTION, Cannot set the value of a calculated field: []

I've done a search for "Cannot set the value of a calculated field" (in quotes) and, believe it or not, it comes up with just one unrelated response.

And no, it's not the obvious - I'm not setting the ID, and if you try to update a formula field, you get the error "Field is not writable" which, as you would expect, returns gazillions of hits when searched.

In terms of being sporadic - it might appear once every week or two. So we're talking maybe one error in >100K upserts on this object. On this one org - nowhere else.

Notice that it doesn't actually say what field is impacted. And, to add to the confusion - this is an upsert of a custom object in a managed package. There are no triggers or workflows on the object.

I'm very much at a loss - without the ability to reproduce it, contacting SFDC support is likely to be a waste of time. So, if anyone has seen this before and has any suggestions or context to provide, I'd greatly appreciate it.

Dan

  • 3
    If/when you catch the DMLException can you use the getDmlFieldNames() method to help isolate the fields. Maybe throw another exception and include the full sObject that was being inserted (Convert to JSON and append to the message). – Daniel Ballinger Apr 2 '14 at 8:19
  • If the error is presented in a page and that org can be left in "Development Mode" (salesforce.stackexchange.com/questions/30094/…) until the error occurs then the stack trace information output might help. – Keith C Apr 2 '14 at 11:52
  • I have to wonder if there isn't a field that requires encryption that's being upserted without first being encrypted. That might produce an error along those lines. I'd be looking at the types of fields on the object to see what's there that might be in the wrong format or requiring special handling of some sort like encryption. Tough one for sure. – crmprogdev Apr 2 '14 at 12:36
  • 1
    1. It's not a DMLException - it's an Unknown exception. The idea of looking at the data being upserted is a good one - though tough in this case to implement (managed package will take a release cycle) 2. It's not on a page, it's being generated in a batch process and we're getting the Email notification. I do know exactly what line it's occurring on - it's an upsert DML operation 3. No encrypted fields on the custom object. Love the way you're all thinking though. – kibitzer Apr 2 '14 at 16:42
  • I'm curious to learn if you got anywhere with this issue. Did SF Support provide any info around the error message? – smohyee Aug 31 '15 at 15:57
2

This was indeed a bug.

I have looked up the related investigations and bug report, and it was resolved in Summer 15.

| improve this answer | |
  • 2
    It's back, this time in the context of trying to be clever and use Formula.recalcuateFormulas() (Winter '20 feature) in a BEFORE trigger (Salesforce doesn't seem to like proceeding to the DML with SObjects that have populated formula field values). – k.. Nov 22 '19 at 0:04

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.