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

Displaying the toast on an Opportunity when another record is created #6

Closed
energidi opened this issue Jun 2, 2022 · 17 comments
Closed

Comments

@energidi
Copy link

energidi commented Jun 2, 2022

Rahul Hi,
First of all, I want to thank you for this great component!

I have a scenario that doesn't trigger the toast.
My use case:
I want to display a toast message to my users based on an exception they receive.
For example, a user tries to update an Opportunity, but the update (process) fails due to a validation rule.
Usually, the (red) exceptions at the button do not provide meaningful information, so I'm trying to display in the toast something more useful for the end-user.
I have an application that creates records every time an exception happens.
What I'm trying to do is as follows:

  1. A user performs an action
  2. An exception is thrown
  3. A new exception custom object record is created
  4. A triggered flow is triggered and creates the toast platform event
  5. The toast LWC component on the Opportunity Lightning Record Page that is subscribed to the Platform Event is triggered and displays the message to the user on the opportunity.

I tried it out but it doesn't work.
It is working when the platform event is created based on the opportunity update, but not when a different object record is created.

Thanks again!
Gidi

@rahulmalhotra
Copy link
Owner

Hi Gidi, as per your use case, I recommend a few things to check:

  1. You're saying that an exception is thrown: Can you confirm once that the exception record is created successfully? The reason I am asking this is because if an exception is thrown, it's possible that the exception record is also rolled back if it's not created in a separate transaction.
  2. As the toast component is present on the opportunity record page, can you check if the parameter RecordId__c is populated in the flow? If yes, it should be populated with the related opportunity id and not the exception record id. If no, it's fine.

Can you check the above and let me know if the issue is still there?

@energidi
Copy link
Author

energidi commented Jun 2, 2022

Hi Rahul,

  1. Yes, the record is created and not rolled out.
  2. I even tried to hardcode the Opportunity ID in the flow, but it didn't work either. I thought it would also work without the ID since we are using the Key__c field that should trigger the LWC component subscribed to the Platform event.

Since the update doesn't succeed (because of the exception), do you think that the toast does not work since the page isn't refreshed?

@rahulmalhotra
Copy link
Owner

Yes, it should work without the id as well. Are you testing this with system admin? If not, does the user possess permission on the ToastEvent__e object?

It should work even if the page is not refreshed. Can you share some more details or maybe screenshots? Did you see any error on the browser console?

@energidi
Copy link
Author

energidi commented Jun 2, 2022

I tested it with my Admin user, so I don't think it's a permission issue.
I also added an email action after the platform event is created and I received the email, so I believe that the platform event was created. I didn't get any errors.
Here's a screenshot of the Record-Triggered create element: https://www.screencast.com/t/mKsy0uXc50P7
Here's a screenshot of the Platform Event Toast settings: https://www.screencast.com/t/8J9AFnXge

@rahulmalhotra
Copy link
Owner

Thank you for sharing the screenshots Gidi, it looks fine. If the platform event is firing, looks like the issue is on the detail page. Ideally, there should be a log printed like: Subscribed to Platform Event Toast when the page is initially loaded, can you check that once?

Also, can you try it once in system mode by checking the Run in System Mode checkbox and confirm if it works?

@energidi
Copy link
Author

energidi commented Jun 2, 2022

Where can I see the log you've mentioned?
I already tried running it in system mode.

@rahulmalhotra
Copy link
Owner

You can see it in browser console. Right click -> Inspect -> Click on Console tab

image

@energidi
Copy link
Author

energidi commented Jun 2, 2022

Thank you, Rahul, for the instructions.
The 'Subscribed to Platform Event toast' message appears in the log.
image

But, there is no toast pop-up.

@energidi
Copy link
Author

energidi commented Jun 2, 2022

I think that I'll try to replicate the scenario in my own developer environment to see if it's working or not.

@rahulmalhotra
Copy link
Owner

Yes, I don't see any issue here. If that still doesn't work, we can probably connect!

@energidi
Copy link
Author

energidi commented Jun 2, 2022

Many thanks, Rahul!

@energidi
Copy link
Author

energidi commented Jun 6, 2022

Rahul Hi,
I've tested it in another environment.
It seems to be working fine.
Not sure what is preventing it from working in my work environment, though.

@rahulmalhotra
Copy link
Owner

Hi Gidi, thank you for the update. Looks like platform events are not firing in the work environment or maybe a permission issue. Can you check once if platform events are fired? Maybe you can have a separate flow/process builder which is running only when the toast platform event is fired and that flow can do some update.

@energidi
Copy link
Author

energidi commented Jun 7, 2022

Rahul Hi,
I've created another flow that is subscribed to the 'Toast Event' Platform Event.
The flow sends an email when the PA is firing.
I received the email, so the PA is definitely firing.
Still, the toast does not appear.

@rahulmalhotra
Copy link
Owner

Can you drop a message on our telegram group. We may connect for 5-10 mins probably over the weekend and resolve it.

@energidi
Copy link
Author

energidi commented Jun 8, 2022

Great, thanks!
I wrote to you there.

@rahulmalhotra
Copy link
Owner

Hi Gidi, I am closing this issue as we discussed it and it's resolved now, feel free to reopen it or create a new one in case you face any problem. Thanks!

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

2 participants