Skip to content

Commit

Permalink
feat(exception email): add log method for email exception data
Browse files Browse the repository at this point in the history
Closes #2
  • Loading branch information
ArturMoczulski committed May 18, 2019
1 parent 487acce commit 79f9b3b
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
12 changes: 12 additions & 0 deletions force-app/main/default/classes/Rollbar.cls
Original file line number Diff line number Diff line change
@@ -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();
Expand All @@ -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();
Expand Down
20 changes: 20 additions & 0 deletions force-app/main/default/tests/RollbarTest.cls
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,24 @@ public class RollbarTest {

System.assertEquals(200, response.getStatusCode());
}

@isTest
public static void testLogExceptionData() {
Test.setMock(HttpCalloutMock.class, new RollbarApiCalloutMock());

Map<String, Object> exDataMap = new Map<String, Object>();
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());
}
}

0 comments on commit 79f9b3b

Please sign in to comment.