diff --git a/force-app/main/default/classes/Rollbar.cls b/force-app/main/default/classes/Rollbar.cls index 11ad14a..25fb1df 100644 --- a/force-app/main/default/classes/Rollbar.cls +++ b/force-app/main/default/classes/Rollbar.cls @@ -1,4 +1,11 @@ +/** + * Installation: + * 1. Add api.rollbar.com in `Remote Sites` in Salesforce Setup. + * 2. Add email service in `Email Services` in Salesforce Setup pointint to RollbarExceptionEmailHandler class. + * 3. Add Salesforce-generated email address from the added email service to `Apex Exception Email` addresses. + */ public with sharing class Rollbar { + public static Rollbar instance() { if (Rollbar.instance == null) { Rollbar.instance = new Rollbar(); @@ -25,6 +32,11 @@ public with sharing class Rollbar { return instance.notifier.log(exc); } + public static HttpResponse log(ExceptionData exData) { + Rollbar instance = initializedInstance(); + return instance.notifier.log(exData); + } + private static Rollbar initializedInstance() { Rollbar instance = Rollbar.instance(); diff --git a/force-app/main/default/tests/RollbarTest.cls b/force-app/main/default/tests/RollbarTest.cls index 422cc32..10451b1 100644 --- a/force-app/main/default/tests/RollbarTest.cls +++ b/force-app/main/default/tests/RollbarTest.cls @@ -19,4 +19,24 @@ public class RollbarTest { System.assertEquals(200, response.getStatusCode()); } + + @isTest + public static void testLogExceptionData() { + Test.setMock(HttpCalloutMock.class, new RollbarApiCalloutMock()); + + Map exDataMap = new Map(); + exDataMap.put('environment', 'Sandbox'); + exDataMap.put('organization', 'TestOrg'); + exDataMap.put('className', 'TestClass'); + exDataMap.put('message', 'Test exception message'); + exDataMap.put('fileName', 'Class.ClassWithExceptionThrown.someMethod'); + exDataMap.put('context', 'Exception context'); + exDataMap.put('line', 14); + exDataMap.put('column', 12); + + Rollbar.init('foo', 'test'); + HttpResponse response = Rollbar.log(ExceptionData.fromMap(exDataMap)); + + System.assertEquals(200, response.getStatusCode()); + } } \ No newline at end of file