• Karel Michek
  • NEWBIE
  • 0 Points
  • Member since 2017

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 2
    Questions
  • 2
    Replies
Hi, I have developed a custom notification in Apex using a page reference to an Aura component, and it works fine (user clicks on notifications under the Bell icon top right and get forwarded to the aura component). But I cannot find a way how to cleanup old notifications, is there a way, please? The system doesn't cleanup automatically, it probably must be done programmatically.
My apex code: 
Messaging.CustomNotification notification = new Messaging.CustomNotification();
notification.setTitle('...');
notification.setBody('...');
notification.setSenderId(UserInfo.getUserId());
notification.setNotificationTypeId([SELECT Id FROM CustomNotificationType WHERE DeveloperName ... LIMIT 1].Id);
User user = [SELECT Id FROM User WHERE ... LIMIT 1];
Map<String, Object> pageRef = new Map<String, Object>{
        'type' => 'standard__component',
        'attributes' => new Map<String, Object>{
                'componentName' => 'c__...'
        },
        'state' => new Map<String, Object>{
                'c__jobId' => ...,
                'c__userId' => ...
        }
notification.setTargetPageRef(JSON.serialize(pageRef));
notification.send(new Set<String>{
        user.Id
});

then the Aura component: 
implemets="flexipage:availableForAllPageTypes,flexipage:availableForRecordHome,force:hasRecordId,lightning:isUrlAddressable">
Hi, I kindly ask for help with setting ContentDistribution password on a published document link. In the Controller I have:

            ContentVersion conVer = new ContentVersion();
            conVer.ContentLocation = 'S'; 
            conVer.PathOnClient = ‘xxx.xls';
            conVer.Title = ‘xxx’;
            conVer.VersionData = excelData;  // taken from VF page which produces XLS document
            insert conVer;

            ContentDistribution cd = new ContentDistribution();
            cd.name = conVer.Title;
            cd.ContentVersionId = conVer.Id;
            cd.PreferencesAllowOriginalDownload = true;
            cd.PreferencesAllowPDFDownload = true;
            cd.PreferencesAllowViewInBrowser = true;
            cd.PreferencesNotifyOnVisit = false;
            // cd.PreferencesPasswordRequired = true; // not sure if required?
         // cd.Password = '123';  // not possible, read only <- maybe set the password here somehow?

Then in the ContentDistributionTrigger:

public override void afterInsert() {

        List<ContentDistribution> afterInsertList = Trigger.New;

        ContentDistribution cd =
            [SELECT DistributionPublicUrl, ContentVersion.ContentDocument.FileType, ContentDocumentId,ContentDownloadUrl
            FROM ContentDistribution
            WHERE Id = :afterInsertList.get(0).Id];

        System.debug(cd.DistributionPublicUrl); // works perfect, but how to protect it with a password?
        System.debug(cd.ContentDownloadUrl);  // works perfect, but how to protect it with a password?
        System.debug('password: '+cd.Password); // empty :-(
}

I don’t mind which way the password should be set, either I pass it to the controller, or it can be auto generated, just can’t find a way in the documentation on how to do it (in Apex).

Thank you very much
Karel
Hi, I have developed a custom notification in Apex using a page reference to an Aura component, and it works fine (user clicks on notifications under the Bell icon top right and get forwarded to the aura component). But I cannot find a way how to cleanup old notifications, is there a way, please? The system doesn't cleanup automatically, it probably must be done programmatically.
My apex code: 
Messaging.CustomNotification notification = new Messaging.CustomNotification();
notification.setTitle('...');
notification.setBody('...');
notification.setSenderId(UserInfo.getUserId());
notification.setNotificationTypeId([SELECT Id FROM CustomNotificationType WHERE DeveloperName ... LIMIT 1].Id);
User user = [SELECT Id FROM User WHERE ... LIMIT 1];
Map<String, Object> pageRef = new Map<String, Object>{
        'type' => 'standard__component',
        'attributes' => new Map<String, Object>{
                'componentName' => 'c__...'
        },
        'state' => new Map<String, Object>{
                'c__jobId' => ...,
                'c__userId' => ...
        }
notification.setTargetPageRef(JSON.serialize(pageRef));
notification.send(new Set<String>{
        user.Id
});

then the Aura component: 
implemets="flexipage:availableForAllPageTypes,flexipage:availableForRecordHome,force:hasRecordId,lightning:isUrlAddressable">
Hi, I kindly ask for help with setting ContentDistribution password on a published document link. In the Controller I have:

            ContentVersion conVer = new ContentVersion();
            conVer.ContentLocation = 'S'; 
            conVer.PathOnClient = ‘xxx.xls';
            conVer.Title = ‘xxx’;
            conVer.VersionData = excelData;  // taken from VF page which produces XLS document
            insert conVer;

            ContentDistribution cd = new ContentDistribution();
            cd.name = conVer.Title;
            cd.ContentVersionId = conVer.Id;
            cd.PreferencesAllowOriginalDownload = true;
            cd.PreferencesAllowPDFDownload = true;
            cd.PreferencesAllowViewInBrowser = true;
            cd.PreferencesNotifyOnVisit = false;
            // cd.PreferencesPasswordRequired = true; // not sure if required?
         // cd.Password = '123';  // not possible, read only <- maybe set the password here somehow?

Then in the ContentDistributionTrigger:

public override void afterInsert() {

        List<ContentDistribution> afterInsertList = Trigger.New;

        ContentDistribution cd =
            [SELECT DistributionPublicUrl, ContentVersion.ContentDocument.FileType, ContentDocumentId,ContentDownloadUrl
            FROM ContentDistribution
            WHERE Id = :afterInsertList.get(0).Id];

        System.debug(cd.DistributionPublicUrl); // works perfect, but how to protect it with a password?
        System.debug(cd.ContentDownloadUrl);  // works perfect, but how to protect it with a password?
        System.debug('password: '+cd.Password); // empty :-(
}

I don’t mind which way the password should be set, either I pass it to the controller, or it can be auto generated, just can’t find a way in the documentation on how to do it (in Apex).

Thank you very much
Karel