3

Currently, I'm using Apex methods to insert, update, and delete records in my Lightning App. These methods call Database class methods which return SaveResult (or DeleteResult). These results can contain an array of errors, making it possible to determine which field an error applies to, and I can then display that particular error message at the correct position on the screen, next to the field it applies to.

I wanted to try using LDS and force:recordData as a way of eliminating some Apex code, and also have components auto-refresh if a record they've loaded gets changed (even outside the app), without having to poll or have the user manually refresh.

However, per the below developer's guide info, it looks like force:recordData only supports one String error message in the form of a targetError attribute:

https://developer.salesforce.com/docs/atlas.en-us.lightning.meta/lightning/aura_compref_force_recordData.htm

I'm guessing if multiple errors are encountered during an insert or update operation, they're all concatenated together in one String, not as discrete errors (like SaveResult has for example).

Has anybody played around with this enough to know for sure? I wanted the ability to handle errors at field-level granularity, and now I'm wondering if LDS supports this?

Thanks for any insight on this.

  • Looks like nobody's run into this before, so I'll probably be some of my own testing next week on how force:recordData presents errors. I'll update this question with my findings. – Florissant53 Jun 20 '17 at 17:36
1

If you're looking for some help with that fairly complex error object, I've got some code for that here:

https://github.com/mshanemc/lightningErrorHandler.

Its function is to traverse the multiple error types (page, field, etc) and errors inside those types to display the correct messages. The error object from force:recordData is the same shape as what comes in Apex callbacks, so this works for both scenarios. #lessBoilerplate

0

force:recordData does support multiple field errors on save. When you call the saveRecord method, you can pass in a function to the callback attribute. When the save is complete, the callback function will be invoked, passing in a SaveRecordResult object.

Errors on save will be part of that object. They will not be part of targetError. targetError is only used for errors that occur while loading records, not performing save or delete.

Properties of the SaveRecordResult object: https://developer.salesforce.com/docs/atlas.en-us.lightning.meta/lightning/data_service_saverecordresult.htm

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.