Skip to content

Instantly share code, notes, and snippets.

@oscartcy
Last active August 29, 2015 14:22
Show Gist options
  • Select an option

  • Save oscartcy/828d497a0f12dbbb36d6 to your computer and use it in GitHub Desktop.

Select an option

Save oscartcy/828d497a0f12dbbb36d6 to your computer and use it in GitHub Desktop.
Testing exeception
Foo up = new Foo(
userId__c = u.Id,
permissions__c = '[]'
);
try {
insert up;
throw new TestException(); // force to run catch block if insert do not throw exception
} catch (Exception e) { // catch exception from insert
System.Assert(e.getMessage().contains('Foo already exist!'));
}
//custom exception declaration
private class TestException extends Exception {}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment