Categories
Appunti

Send custom notification in Apex of Salesforce

Map<String, Schema.SObjectType> m  = Schema.getGlobalDescribe() ;
        Schema.SObjectType s = m.get('Account') ;
        Schema.DescribeSObjectResult r = s.getDescribe() ;
        String keyPrefix = r.getKeyPrefix();

        Map<String, Object> lightningPageRef = new Map<String, Object>{
            'type' => 'standard__namedPage',
            'attributes' => new Map<String, Object>{
                'pageName' => 'home'
            }
        };

Id typeId = '0ML1l00000001dxGAA';
        Messaging.CustomNotification notification = new Messaging.CustomNotification();
        notification.setTitle('test title');
        notification.setBody('test body');        
        notification.setSenderId(Userinfo.getUserId());
        notification.setNotificationTypeId(typeId );        
        notification.setTargetPageRef(JSON.serialize(lightningPageRef));
        notification.send(new Set<String> { Userinfo.getUserId() }); 

Leave a Reply