• Jung Mun
  • NEWBIE
  • 5 Points
  • Member since 2019

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 3
    Questions
  • 5
    Replies
@isTest
    static void sendNotificationTest(){
        Boolean exceptionThrown = false;
        try{
        ProductHandler.sendNotification('invalidemail@0284hgwfekb.com','Mock Product  Name',null);
        Boolean expectedExceptionThrown =  (e.getMessage().length() == null) ? true : false; 
        System.AssertEquals(true, expectedExceptionThrown, e.getMessage()); 
        } catch (Exception e){
        exceptionThrown = true;
        expectedExceptionThrown =  (e.getMessage().length() != null) ? true : false; 
        System.AssertEquals(true, expectedExceptionThrown, e.getMessage()); 
        }
        System.assertEquals(true,exceptionThrown,'User got notified about the newly added product');
    }

Hi,
I was wondering if you can share an example of writing a negative unit test for a custom notification method. What would be the scenario in which the notification failed to send? EmailException error is generated first before Exception error. How can I get 100% code coverage?
@testVisible
    private static void sendNotification(String recipientId,String productName,String TargetId){
        // query custom notification for Product Exists alert
        CustomNotificationType notificationType = [SELECT id,customNotifTypeName FROM CustomNotificationType WHERE DeveloperName = 'Product_Exists'];
        // get running user ID
        Set<String> recipientsIds = new Set<String>{recipientId};
        // create a new instance of Messaging.CustomNotification class with new custom notification
        try {
        Messaging.CustomNotification notification = new Messaging.CustomNotification();
        notification.setTitle('New Product : ' + ProductName + ' is added to inventory');
        notification.setBody('New Product  : ' + ProductName + ' is added');
        notification.setSenderId(recipientId);

        // Set the notification type and target
        notification.setNotificationTypeId(notificationType.Id);
        notification.setTargetId(targetId);
        
        // Actually send the notification
        
            notification.send(recipientsIds);
        }
        catch (Exception e) {
            System.debug('Problem sending notification: ' + e.getMessage());
        }

    }


This is an example of a positive unit test though I wish to convert to a negative unit test.
 

Hi! Our org has 50+ workflow rules assigned to one custom object that I made a consolidated version with one process builder instance. After finishing with sandbox testing and on debug testing, business logics that are built with one process builder consumed more characters and CPU time when I executed one condition to meet one criteria. 

Process builder is .5-1 second slower than the workflow and runs 100,000 characters more. Which one is better? having 50+ workflows or slow performance? Is there any third solution?

Thanks

Jung

 

Hi!
I am using a new DE trailhead and here is my error code.
Let me know what would be the problem with this.

Challenge Not yet complete... here's what's wrong: 
There was an unexpected error while verifying this challenge. Usually this is due to some pre-existing configuration or code in the challenge Org. We recommend using a new Developer Edition (DE) to check this challenge. If you're using a new DE and seeing this error, please post to the developer forums and reference error id: DMJLOZDA

Jung
@isTest
    static void sendNotificationTest(){
        Boolean exceptionThrown = false;
        try{
        ProductHandler.sendNotification('invalidemail@0284hgwfekb.com','Mock Product  Name',null);
        Boolean expectedExceptionThrown =  (e.getMessage().length() == null) ? true : false; 
        System.AssertEquals(true, expectedExceptionThrown, e.getMessage()); 
        } catch (Exception e){
        exceptionThrown = true;
        expectedExceptionThrown =  (e.getMessage().length() != null) ? true : false; 
        System.AssertEquals(true, expectedExceptionThrown, e.getMessage()); 
        }
        System.assertEquals(true,exceptionThrown,'User got notified about the newly added product');
    }

Hi,
I was wondering if you can share an example of writing a negative unit test for a custom notification method. What would be the scenario in which the notification failed to send? EmailException error is generated first before Exception error. How can I get 100% code coverage?
@testVisible
    private static void sendNotification(String recipientId,String productName,String TargetId){
        // query custom notification for Product Exists alert
        CustomNotificationType notificationType = [SELECT id,customNotifTypeName FROM CustomNotificationType WHERE DeveloperName = 'Product_Exists'];
        // get running user ID
        Set<String> recipientsIds = new Set<String>{recipientId};
        // create a new instance of Messaging.CustomNotification class with new custom notification
        try {
        Messaging.CustomNotification notification = new Messaging.CustomNotification();
        notification.setTitle('New Product : ' + ProductName + ' is added to inventory');
        notification.setBody('New Product  : ' + ProductName + ' is added');
        notification.setSenderId(recipientId);

        // Set the notification type and target
        notification.setNotificationTypeId(notificationType.Id);
        notification.setTargetId(targetId);
        
        // Actually send the notification
        
            notification.send(recipientsIds);
        }
        catch (Exception e) {
            System.debug('Problem sending notification: ' + e.getMessage());
        }

    }


This is an example of a positive unit test though I wish to convert to a negative unit test.
 

Hi! Our org has 50+ workflow rules assigned to one custom object that I made a consolidated version with one process builder instance. After finishing with sandbox testing and on debug testing, business logics that are built with one process builder consumed more characters and CPU time when I executed one condition to meet one criteria. 

Process builder is .5-1 second slower than the workflow and runs 100,000 characters more. Which one is better? having 50+ workflows or slow performance? Is there any third solution?

Thanks

Jung

 

Hi!
I am using a new DE trailhead and here is my error code.
Let me know what would be the problem with this.

Challenge Not yet complete... here's what's wrong: 
There was an unexpected error while verifying this challenge. Usually this is due to some pre-existing configuration or code in the challenge Org. We recommend using a new Developer Edition (DE) to check this challenge. If you're using a new DE and seeing this error, please post to the developer forums and reference error id: DMJLOZDA

Jung

I am following the guidelines from the Chatter guide and somehow I can't get the OAuth to work. 

 

It's not working from Java or curl.   Here is what I am doing:

 

mike$ curl --form client_id=3MVG9yZ.WNe6bxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxu5AjB4oT9kxi8SEhY --form client_secret=26542xxxxxxxxxxx78  --form grant_type=password --form username=xxxxxxxx@gmail.com --form password=xxxxxxx https://na11.salesforce.com/services/oauth2/token

 

What I am getting is:

{"error":"invalid_grant","error_description":"authentication failure - Invalid Password"}

 

I double checked and I am getting into na11 with the right password.  Is there anything else I need to do?

 

Here are the settings in my remote access:

 



Applicationchatter



Callback URLhttps://na11.salesforce.com/ConnectTest/oauth/_callback /// temp one



No user approval required for users in this organizationNot Checked