In release Winter'21 was introduced new Target option for Custom Notifications (see here).
I would like to have a specific Community page as Target Page Reference. Still, I can't figure out the format I need to put into the Target Page Reference attribute on Custom Notification action. Every format I try makes the flow fail with the error Invalid parameter value for: targetPageRef
. I would like to navigate to the Community Home page. Any suggestion?
-
1I've had a similar issue and have tried the following: 1) a string with a partial URL, 2) An apex instance of a pagereference with the partial URL, 3) the getURL() method on that pagereference.– BigearsCommented Oct 17, 2020 at 11:50
-
@Bigears did any of that work?– mascotCommented Oct 20, 2020 at 12:08
-
1No, it didn't. I was just adding my experience. Apologies for not being clearer. However, the answer below worked for me and I've been able to navigate as I need to pages within the community.– BigearsCommented Oct 21, 2020 at 18:54
3 Answers
It seems that targetPageRef
is expecting lightning pageReference types in a string format, so if you pass the otherwise json as a string, like the following:
"{"type": "standard__objectPage","attributes": {"objectApiName": "Task","actionName": "list"},"state":{"filterName":"Recent"}}"
you'll be redirected to the listview of the recent Task records when clicking the notification.
-
I would like to navigate to the community Home page. Do you have any suggestion on how to achieve that?– mascotCommented Oct 20, 2020 at 12:10
-
1@mascot to reference a community home, page the type
comm__namedPage
must be used, followed by the "Home" value in thename
attribute. So the string"{"type": "comm__namedPage","attributes": {"name": "Home"}}"
should cover your use case.– zigzigCommented Oct 21, 2020 at 16:39 -
Hi @zigzig, I'm struggling to get this to work here salesforce.stackexchange.com/questions/331750/… via the new Apex API trying just the JSON string. Any thoughts?– Keith CCommented Jan 20, 2021 at 11:21
Thanks to @Keith for answer here For redirecting in communities you can use the below code.
private final Map<String, Object> communityPageRef = new Map<String, Object>{
'type' => 'comm__namedPage',
'attributes' => new Map<String, Object>{
'pageName' => 'home'
}
};
customNotification.setTargetPageRef(JSON.serialize(communityPageRef));
If you are on a console tab in lightning and you want to navigate to home page then use this.
private final Map<String, Object> lightningPageRef = new Map<String, Object>{
'type' => 'standard__namedPage',
'attributes' => new Map<String, Object>{
'pageName' => 'home'
}
};
customNotification.setTargetPageRef(JSON.serialize(lightningPageRef));
Figured I'd add this as nobody online seem to say it regarding where you need to put that in flow. You can paste that code into a text template variable (make sure it's set as plain text), then use that variable in the send custom notification action under Target Page Reference.