DatatableV2 icon indicating copy to clipboard operation
DatatableV2 copied to clipboard

Data table not working if Id field on record is not set

Open patrickbrinksma opened this issue 5 years ago • 16 comments

Hi Eric, we just starting using the component - so many thanks for making it available - but we hit a (known) issue. Use case:

  1. We create a record collection of the object ProductRequestLineItem (yes, it has geolocation field)
  2. We want to use the data table to show the records (which are NOT yet inserted)

This doesn't work, error: SObject cannot be read

When I query existing records from ProductRequestLineItem, it does work.

Is this the known limitation?

Appreciate your reply.

patrickbrinksma avatar Jul 16 '20 16:07 patrickbrinksma

Eric, the "funny" thing is that when I assign the ProductRequestLineItem.Id to a valid Id (which does NOT exist as a record anymore), it seems to work fine. Appreciate your thoughts on this.

patrickbrinksma avatar Jul 16 '20 16:07 patrickbrinksma

Eric, update:

I added a method to generate a "fake" id for an SObject which you can call from flow using the method of Financial Force library which can be found here: https://github.com/apex-enterprise-patterns/fflib-apex-mocks/blob/master/sfdx-source/apex-mocks/main/classes/fflib_IDGenerator.cls.

I adopted the method to be called from a Flow, and return a record Id, and then the data table works fine. If you're interested in the code, let me know.

patrickbrinksma avatar Jul 17 '20 13:07 patrickbrinksma

That's a great workaround. I'd love to see your solution.

Eric

On Fri, Jul 17, 2020 at 9:19 AM Patrick Brinksma [email protected] wrote:

Eric, update:

I added a method to generate a "fake" id for an SObject which you can call from flow using the method of Financial Force library which can be found here: https://github.com/apex-enterprise-patterns/fflib-apex-mocks/blob/master/sfdx-source/apex-mocks/main/classes/fflib_IDGenerator.cls .

I adopted the method to be called from a Flow, and return a record Id, and then the data table works fine. If you're interested in the code, let me know.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/ericrsmith35/DatatableV2/issues/7#issuecomment-660102974, or unsubscribe https://github.com/notifications/unsubscribe-auth/AF4UHX5HJRZNZHW6W4QOUZDR4BFWDANCNFSM4O4SHD3A .

ericrsmith35 avatar Jul 17 '20 17:07 ericrsmith35

Eric,

I create a fork, and put the additions in a separate branch. So I added a method "generateSObjectId" here https://github.com/patrickbrinksma/DatatableV2/blob/VirtualSalesforceId/force-app/main/default/classes/SObjectController2.cls which you can call from a Flow, and also added a test method here: https://github.com/patrickbrinksma/DatatableV2/blob/VirtualSalesforceId/force-app/main/default/classes/SObjectController2Test.cls

Let me know if you can access these.

In the flow, for each new record you want to "preview", you call this method with a counter and the API Name of the SObject.

patrickbrinksma avatar Jul 20 '20 11:07 patrickbrinksma

Well done. I'll add this to the roadmap for a future release.

Eric

On Mon, Jul 20, 2020 at 7:48 AM Patrick Brinksma [email protected] wrote:

Eric,

I create a fork, and put the additions in a separate branch. So I added a method "generateSObjectId" here https://github.com/patrickbrinksma/DatatableV2/blob/VirtualSalesforceId/force-app/main/default/classes/SObjectController2.cls which you can call from a Flow, and also added a test method here: https://github.com/patrickbrinksma/DatatableV2/blob/VirtualSalesforceId/force-app/main/default/classes/SObjectController2Test.cls

Let me know if you can access these.

In the flow, for each new record you want to "preview", you call this method with a counter and the API Name of the SObject.

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/ericrsmith35/DatatableV2/issues/7#issuecomment-660979224, or unsubscribe https://github.com/notifications/unsubscribe-auth/AF4UHX67SQAVJD7X3IDVX43R4QVKDANCNFSM4O4SHD3A .

ericrsmith35 avatar Jul 20 '20 17:07 ericrsmith35

Hi Eric, wanted to make you aware of an update. We had a required to show a list of uncommitted records, and so I refactored the method to allow for the creation of a collection of "virtual" object ids.

So you would determine in the flow how many record ids you need, call the Apex Action once, and get a collection of Object Ids back.

Code is available in the fork.

patrickbrinksma avatar Jul 30 '20 13:07 patrickbrinksma

Thanks for the update.

On Thu, Jul 30, 2020 at 9:07 AM Patrick Brinksma [email protected] wrote:

Hi Eric, wanted to make you aware of an update. We had a required to show a list of uncommitted records, and so I refactored the method to allow for the creation of a collection of "virtual" object ids.

So you would determine in the flow how many record ids you need, call the Apex Action once, and get a collection of Object Ids back.

Code is available in the fork.

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/ericrsmith35/DatatableV2/issues/7#issuecomment-666353167, or unsubscribe https://github.com/notifications/unsubscribe-auth/AF4UHXYFEHXFODLUDMMCWC3R6FWB7ANCNFSM4O4SHD3A .

ericrsmith35 avatar Jul 30 '20 13:07 ericrsmith35

Hi Eric, I stumbled upon the same problem while writing a mass upserter for a custom object (which mixes existing and new records in a record collection). Do you remember the last commit or version, where this worked?

clifford-fra avatar Aug 19 '20 14:08 clifford-fra

Clifford - the only version I know of that supports this would be the changed version that Patrick created.

On Wed, Aug 19, 2020 at 10:34 AM Clifford [email protected] wrote:

Hi Eric, I stumbled upon the same problem while writing a mass upserter for a custom object (which mixes existing and new records in a record collection). Do you remember the last commit or version, where this worked?

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/ericrsmith35/DatatableV2/issues/7#issuecomment-676457795, or unsubscribe https://github.com/notifications/unsubscribe-auth/AF4UHXYHPMN7UZAYPX4MHT3SBPPH5ANCNFSM4O4SHD3A .

ericrsmith35 avatar Aug 19 '20 14:08 ericrsmith35

Clifford, happy to share the code, just let me know.

patrickbrinksma avatar Aug 19 '20 15:08 patrickbrinksma

Thanks patrick, I saw your code in commit 7f09fb5bbde350592b888dd7ddf3f0231efab3ee but think it won't work well with my Mass Upserter usecase. I will probably go the long way and use a custom apex object

clifford-fra avatar Aug 19 '20 16:08 clifford-fra

Clifford, in a later commit, 5d1ec01c1f95b5e381caca7ed82b7cbd5efb7427, I adjusted to code to be able to return a collection of Ids, not sure if that helps in your use case.

patrickbrinksma avatar Aug 20 '20 05:08 patrickbrinksma

Patrick,

Correct me if I am wrong, but it sounds like you are setting Id to the value from your generator in the collection elsewhere in the flow before the collection is displayed in the data table, correct? If the purpose of the data table is to display data to be inserted, then wouldn't you also have to strip the Id out of the collection before doing the actual insert step?

Erik,

I love the data table component. In some of my use cases, I am weighing whether to pursue modifying my flow to manage handling Ids for records to be inserted or waiting for your update which I am guessing will just assign the ids temporarily before passing the records back to the output collection? If that is the intent, do you know when that future release might happen?

Thanks

mikbranchaud avatar Oct 02 '20 13:10 mikbranchaud

I don't have a timeframe yet for adding this feature.

On Fri, Oct 2, 2020 at 9:26 AM mikbranchaud [email protected] wrote:

Patrick,

Correct me if I am wrong, but it sounds like you are setting Id to the value from your generator in the collection elsewhere in the flow before the collection is displayed in the data table, correct? If the purpose of the data table is to display data to be inserted, then wouldn't you also have to strip the Id out of the collection before doing the actual insert step?

Erik,

I love the data table component. In some of my use cases, I am weighing whether to pursue modifying my flow to manage handling Ids for records to be inserted or waiting for your update which I am guessing will just assign the ids temporarily before passing the records back to the output collection? If that is the intent, do you know when that future release might happen?

Thanks

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/ericrsmith35/DatatableV2/issues/7#issuecomment-702733189, or unsubscribe https://github.com/notifications/unsubscribe-auth/AF4UHX7TWD7CM2JNHSCJRALSIXII3ANCNFSM4O4SHD3A .

ericrsmith35 avatar Oct 02 '20 13:10 ericrsmith35

@mikbranchaud that is correct. First retrieve the collections of Ids, create the collection of records to be inserted, and assign each an Id. If you want to insert the records, I think you'd have to blank the Id value. I haven't tested it in much detail to be honest as it was a proof of concept I did it for.

patrickbrinksma avatar Oct 02 '20 13:10 patrickbrinksma

I am also attempting to display a records collection prior to creation, and while I am very grateful for this workaround, wouldn't it be simpler to simply remove the restriction preventing the display of records without an id?

Or is that hardcoded/required somewhere deep in the component itself and creating mock ids is the only way to make it work? It just seems like an awfully complex way to get around what could be a simple restriction.

aKasperavicius avatar Dec 01 '20 15:12 aKasperavicius