Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
patrickbrinksma opened this issue Jul 16, 2020 · 16 comments
Open

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

patrickbrinksma opened this issue Jul 16, 2020 · 16 comments

Comments

@patrickbrinksma
Copy link

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
Copy link
Author

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
Copy link
Author

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.

@ericrsmith35
Copy link
Owner

ericrsmith35 commented Jul 17, 2020 via email

@patrickbrinksma
Copy link
Author

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.

@ericrsmith35
Copy link
Owner

ericrsmith35 commented Jul 20, 2020 via email

@patrickbrinksma
Copy link
Author

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.

@ericrsmith35
Copy link
Owner

ericrsmith35 commented Jul 30, 2020 via email

@clifford-fra
Copy link

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?

@ericrsmith35
Copy link
Owner

ericrsmith35 commented Aug 19, 2020 via email

@patrickbrinksma
Copy link
Author

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

@clifford-fra
Copy link

Thanks patrick, I saw your code in commit 7f09fb5 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

@patrickbrinksma
Copy link
Author

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

@mikbranchaud
Copy link

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

@ericrsmith35
Copy link
Owner

ericrsmith35 commented Oct 2, 2020 via email

@patrickbrinksma
Copy link
Author

@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.

@aKasperavicius
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants