How to create notifications safely on the active page in Business Central using AL?

var 
      MyNotification: Notification;
    
    local procedure ShowNotification()
    var
        NotificationMessage: Label 'Your Notification Message.';
    begin
        MyNotification.Scope := NotificationScope::LocalScope;
        MyNotification.Message := NotificationMessage;
        if ShouldNotify then
            MyNotification.Send()
        else
            if not (IsNullGuid(MyNotification.Id)) then
                MyNotification.Recall();
    end;
codeunit 50100 "Counter Management" and interface ICounterManagement

What is important to note is that you must do a IsNullGuid check before you attempt to recall your notification. If there is no active notification, it will shoot an error message.

Reference -

https://docs.microsoft.com/en-us/dynamics365/business-central/dev-itpro/developer/devenv-notifications-developing

https://docs.microsoft.com/en-us/dynamics365/business-central/dev-itpro/developer/methods-auto/guid/guid-data-type