Bell icon in communities: syntax of the setTargetPageRef string?

I could see it working (outside of Communities, I have not tried that part yet) with the following scenarios:

  • Named Page Type (type = standard__namedPage): quite limited but useful.
  • Item Page Type (type = standard__navItemPage): navigates to tabs.
  • Record Page Type (type = standard__recordPage): navigates to a records, in modes such as view, edit (my example), and clone.

Conclusion so far: it seems that the comment from Bartheleway, setTargetPageRef using JSON format syntax is correct, based on my tests, at least.

Note: thanks for the references shared, that LWC PageReference Types & CustomNotification Class references served as the basis of the tests I made.

Code to send a notification to the current user:

// Named Page Type. Drives to Home Page.
/*String addressTest = 
'' +
'    {' +
'        type: \'standard__namedPage\', ' +
'        attributes: {' +
'            pageName: \'home\'' +
'        }'+
'   }'+
'';*/

// Item Page Type. Drives to a custom tab named NotificationTab.
/*String addressTest = 
'' +
'    {' +
'        type: \'standard__navItemPage\', ' +
'        attributes: {' +
'            apiName: \'NotificationTab\'' +
'        }'+
'   }'+
'';*/

// Record Page Type. Drives to the edit page for the given Account record id.
String addressTest = 
'' +
'{' +
'       type: \'standard__recordPage\',' +
'       attributes: {' +
'           recordId: \'0012X000022RUSLQA4\',' +
'           objectApiName: \'Account\',' +
'           actionName: \'edit\'' +
'       }' +
'}';

// Get the Id for our custom notification type
CustomNotificationType notificationType = 
    [SELECT Id, DeveloperName 
        FROM CustomNotificationType 
        WHERE DeveloperName = 'Custom_Notification'];

// Create a new custom notification
Messaging.CustomNotification notification = new Messaging.CustomNotification();
notification.setTitle('Apex Custom Notification');
notification.setBody('The notifications are coming from INSIDE the Apex!');
notification.setNotificationTypeId(notificationType.Id);
notification.setTargetPageRef(addressTest);

// Actually send the notification
try {
    notification.send(new Set<String>{UserInfo.getUserId()});
}
catch (Exception e) {
    System.debug('Problem sending notification: ' + e.getMessage());
}