1

Having managed to get notifications to appear by not including a "state" and so using:

Map<String, Object> pageRef = new Map<String, Object>{
    'type' => 'comm__namedPage',
    'attributes' => new Map<String, Object>{
        'name' => 'cvcp__event-details'
    }
};
notification.setTargetPageRef(JSON.serialize(pageRef));

a click on a notification item generates a browser error (in Chrome) of e.g.:

Refused to run the JavaScript URL because it violates the following Content Security Policy directive: "script-src 'self' 'unsafe-eval' 'nonce-GzsQXTm1bMh16s0QBEqIhyq4Vrp152Im' https://service.force.com/embeddedservice/ import: blob:". Either the 'unsafe-inline' keyword, a hash ('sha256-...'), or a nonce ('nonce-...') is required to enable inline execution.

The Salesforce Platform generated link is:

<a class="notification-link" href="javascript:void(0)" ...>
    ...
</a>

So this is probably an irrelevant error?

There is a successful POST request made to:

https://.../portal/s/sfsites/aura?r=14&ui-notifications-components-notifications-controller.Notifications.markNotificationRead=1

at the same time but that looks like just an update that the notification has been read.

One related post is lightning:navigation not passing the States in URL.

Does anyone understand what part here makes the navigation occur and what I can try to make the navigation work?

1 Answer 1

2

I tried the "comm__namedPage" approach shown in the question with names of:

  • cvcp__event-details
  • c__event-details
  • event-details

and none of those worked.

What did work, and with the benefit of being able to inject query parameters (that I would have preferred to use "state" for but the API does not allow that) was:

Map<String, Object> pageRef = new Map<String, Object>{
    'type' => 'standard__webPage',
    'attributes' => new Map<String, Object> {
        'url' => '/portal/s/event-details?eventId=a0756000005VLI3AAO'
    }
};
notification.setTargetPageRef(JSON.serialize(pageRef));

So I will be using his approach for now. (The CSP console log error shown in the question is still output but the navigation works.)

4
  • for us this worked Map<String, Object> pageRef = new Map<String, Object>{ 'type' => 'comm__namedPage', 'attributes' => new Map<String, Object>{ 'pageName' => 'home' }}; for navigating to home Commented Feb 19, 2021 at 4:13
  • Thanks @NagendraSingh; good to know it works fine for a standard page name. Do you have any examples of custom page names?
    – Keith C
    Commented Feb 19, 2021 at 10:18
  • It does work for with Page api name, for redirecting it to required page, but as you said there is no way to include query params in that. Commented Feb 19, 2021 at 11:40
  • Thanks @NagendraSingh.
    – Keith C
    Commented Feb 19, 2021 at 13:43

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .